Search categories, packages and repositories

Package detailsv2.3.1

random_string

Simple library for generating random ascii strings by default using Random from 'dart:math'.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
165K
Likes
203
Pub points
160

Install package

flutter pub add random_string

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A simple Flutter/Dart package for generating random ASCII strings using Dart's built-in Random class. It provides an easy-to-use API to create random strings of specified lengths, ideal for scenarios like generating temporary tokens, passwords, or identifiers. The library is lightweight and platform-agnostic, supporting all major platforms including Android, iOS, Web, macOS, Windows, and Linux. It requires no external dependencies beyond the core Dart SDK.

Use cases

  • Generating temporary passwords
  • Creating unique identifiers
  • Producing test data
  • Token generation for authentication
  • Simulating random input in apps

Key features

  • Simple API with minimal setup
  • Uses Dart's Random class
  • Supports custom length and character sets
  • Cross-platform compatibility
  • Lightweight and dependency-free

Suitable for

  • Developers needing quick random string generation
  • Testing and prototyping
  • Authentication and session management
  • Apps requiring unique IDs or codes

Considerations

  • Limited to ASCII characters by default
  • No cryptographic security guarantees
  • Does not support Unicode or special character customization without extension

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package