ID Generator

A comprehensive Dart library for generating secure, customizable random IDs with support for numeric, alphabetic, special characters, and mixed combinations.

Pub Version Dart SDK License

✨ Features

  • πŸ”’ Numeric IDs: Generate IDs using digits 1-9 (excludes 0 for clarity)
  • πŸ”€ Alphabetic IDs: Generate IDs with mixed case letters (a-z, A-Z)
  • πŸ”£ Special Character IDs: Generate IDs using safe special characters
  • 🎭 Mixed IDs: Combine all character types for maximum entropy
  • 🎯 Custom Mix: Create IDs with user-defined character type combinations
  • πŸ“¦ Batch Generation: Efficiently generate multiple IDs at once
  • πŸ”’ Secure: Uses Dart's cryptographically secure Random class
  • ⚑ Fast: Optimized for performance with minimal overhead

πŸš€ Getting Started

Installation

Add this package to your pubspec.yaml:

dependencies:
  id_generator: latest # Use latest version

πŸ’‘ Always latest: Using latest ensures you get the most current version. You can also use ^1.0.0 for semantic versioning or check pub.flutter-io.cn for specific version numbers.

Then run:

dart pub get

Import

import 'package:id_generator/id_generator.dart';

πŸ“– Usage

Basic Examples

Numeric IDs

// Generate a 8-character numeric ID
String numericId = IDGenerator.generateNum(8);
print(numericId); // Example: "47382951"

// Generate multiple numeric IDs
List<String> numericIds = IDGenerator.listOfNums(3, 6);
print(numericIds); // Example: ["473829", "194756", "829374"]

Alphabetic IDs

// Generate a 10-character alphabetic ID
String alphaId = IDGenerator.generateAlpha(10);
print(alphaId); // Example: "aBcDeFgHiJ"

// Generate multiple alphabetic IDs
List<String> alphaIds = IDGenerator.listOfAlpha(2, 8);
print(alphaIds); // Example: ["aBcDeFgH", "XyZaBcDe"]

Special Character IDs

// Generate a 6-character special character ID
String specialId = IDGenerator.generateSpecial(6);
print(specialId); // Example: "!@#$%^"

// Generate multiple special character IDs
List<String> specialIds = IDGenerator.listOfSpecial(2, 4);
print(specialIds); // Example: ["!@#$", "^&*_"]

Advanced Usage

Mixed IDs (All Character Types)

// Generate a 12-character mixed ID
String mixedId = IDGenerator.mix(12);
print(mixedId); // Example: "a7$bC3@dE9!f"

// Generate multiple mixed IDs
List<String> mixedIds = IDGenerator.listOfMix(5, 8);
print(mixedIds); // Example: ["a7$bC3@d", "E9!fG2#h", "K4%mN8&p", ...]

Custom Character Type Combinations

// Generate ID with only numbers and letters (no special chars)
String customId = IDGenerator.customMix(10, [IdgEnum.nums, IdgEnum.alpha]);
print(customId); // Example: "a7bC3dE9fG"

// Generate IDs with only special characters and numbers
List<String> customIds = IDGenerator.listOfCustomMix(
  3, 6, [IdgEnum.special, IdgEnum.nums]
);
print(customIds); // Example: ["!@1#2$", "3%4^5&", "*6_7-8"]

// Generate ID with only alphabetic characters
String alphaOnlyId = IDGenerator.customMix(8, [IdgEnum.alpha]);
print(alphaOnlyId); // Example: "aBcDeFgH"

🎯 Use Cases

  • Session IDs: Secure session identifiers for web applications
  • API Keys: Generate random API keys and tokens
  • File Names: Create unique file names to avoid conflicts
  • Database IDs: Alternative to auto-incrementing primary keys
  • Temporary Passwords: Generate temporary passwords for user accounts
  • Unique Identifiers: Any scenario requiring unique string identifiers
  • Testing: Generate test data with random identifiers

πŸ“Š Character Sets

Type Characters Count Example
Numeric 1-9 9 473829
Alphabetic a-z, A-Z 52 aBcDeFgH
Special - _ ! @ # $ % ^ & * 10 !@#$%^
Mixed All above combined 71 a7$bC3@d

Note: The digit 0 is intentionally excluded from numeric IDs to avoid confusion with the letter O in certain contexts.

⚑ Performance

The ID Generator is optimized for performance:

  • Single ID Generation: ~0.1ms for typical lengths (8-16 characters)
  • Batch Generation: ~50% faster than individual calls for multiple IDs
  • Memory Efficient: Minimal memory allocation during generation
  • Thread Safe: All methods are thread-safe and can be used concurrently

πŸ”’ Security Considerations

  • Uses Dart's Random class which provides cryptographically secure randomness
  • Generated IDs have high entropy making them suitable for security-sensitive applications
  • Character sets are carefully chosen to avoid common confusion issues
  • No predictable patterns in generated sequences

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

  1. Clone the repository
  2. Run dart pub get to install dependencies
  3. Run dart test to execute tests
  4. Run dart analyze to check for issues

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ˆ Changelog

See CHANGELOG.md for a detailed list of changes and version history.


Made with ❀️ for the Dart community

Libraries

id_generator
A comprehensive Dart library for generating secure, customizable random IDs.