搜尋分類、套件與程式碼儲存庫

套件詳情v2.3.1

random_string

一個簡單的庫,預設使用 'dart:math' 中的 Random 來產生隨機 ASCII 字串。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
16.5萬
喜歡數
203
Pub 分數
160

安裝套件

flutter pub add random_string

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個簡單的 Flutter/Dart 套件,使用 Dart 內建的 Random 類來產生隨機 ASCII 字串。它提供了一個易於使用的 API,可建立指定長度的隨機字串,非常適合用於產生暫時性金鑰、密碼或識別碼等情境。此套件輕量且與平台無關,支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。除了核心 Dart SDK 外,不需要任何外部相依性。

適用情境

  • 產生臨時密碼
  • 創建唯一標識符
  • 產生測試資料
  • 用於身分驗證的權杖產生
  • 在應用程式中模擬隨機輸入

主要特色

  • 簡單的 API,設定簡單
  • 使用 Dart 的 Random 類
  • 支援自定長度和字元集
  • 跨平台相容性
  • 輕量且無依賴

適合對象

  • 需要快速產生隨機字串的開發者
  • 測試和原型設計
  • 身份驗證和會話管理
  • 需要唯一 ID 或代碼的應用程式

使用建議

  • 預設僅限於 ASCII 字符
  • 無加密安全保證
  • 不支援Unicode或特殊字元自定,除非使用擴充

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

random_string

Simple library for generating random ascii strings.

Design goals and limitations

While this package provides randomBetween for convenience, as the name implies, the design goal of this package is for random generation of ascii strings, particularly for testing and not for cryptographic purposes.
With that stated, consider an alternative means of random number generation if your needs fall outside these goals and limitations.

Usage

A simple usage example:

import 'package:random_string/random_string.dart';
import 'dart:math' show Random;

main() {
  print(randomBetween(10, 20)); // some integer between 10 and 20 where 0 <= min <= max <= 999999999999999
  print(randomNumeric(4)); // sequence of 4 random numbers i.e. 3259
  print(randomString(10)); // random sequence of 10 characters i.e. e~f93(4l-
  print(randomAlpha(5)); // random sequence of 5 alpha characters i.e. aRztC
  print(randomAlphaNumeric(10)); // random sequence of 10 alpha numeric i.e. aRztC1y32B

  var r = Random.secure();
  print(randomBetween(10, 20, provider: CoreRandomProvider.from(r))); // You can use a provider from Random.
  print(randomBetween(10, 20, provider: _Provider())); // Or you can implement your own.
}

class _Provider with AbstractRandomProvider {
  _Provider();
  double nextDouble() => 0.5;
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

所屬分類

原始碼儲存庫

使用此套件的專案