搜索分类、插件与代码仓

插件详情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.

所属分类

源码仓库

使用此插件的项目