taranovegor/string-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

taranovegor/string-generator

Composer 安装命令:

composer require taranovegor/string-generator

包简介

Fast, cryptographically-secure random string generator with predefined ASCII alphabets

README 文档

README

CI PHPStan Level 9 PHP 8.2+ License: MIT

Fast, cryptographically-secure random string generator for PHP 8.2+.

Zero external dependencies. Uses random_bytes() with bit-packing and rejection sampling for efficient, unbiased output.

Installation

composer require taranovegor/string-generator

Quick start

use TaranovEgor\StringGenerator\Alphabet;
use TaranovEgor\StringGenerator\StringGenerator;

$generator = new StringGenerator();

// Default — alphanumeric (a-zA-Z0-9)
$token = $generator->generate(32);

// Digits only
$pin = $generator->generate(6, Alphabet::Digits);

// Letters only
$code = $generator->generate(16, Alphabet::Alpha);

// All printable ASCII
$password = $generator->generate(20, Alphabet::Printable);

All predefined alphabets

Case Characters Size
Digits 0-9 10
AlphaLower a-z 26
AlphaUpper A-Z 26
Alpha a-z A-Z 52
Alphanumeric a-z A-Z 0-9 62
Punctuation 32 punctuation characters (`!"#$%&'()*+,-./:;<=>?@[]^_{ }~`)
Printable All printable ASCII (33–126) 94

Custom alphabet

Pass a string as the second argument — every byte in it becomes a valid character:

$generator = new StringGenerator();

// Hex string
echo $generator->generate(32, '0123456789abcdef');

// Base58
echo $generator->generate(22, '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');

// Binary-safe — works with any byte values, including null bytes
echo $generator->generate(64, "\x00\x01\x02\x03");

Note: the alphabet must contain at least 2 distinct bytes.

Development

composer install

# Run tests
composer test

# Static analysis (PHPStan level 9)
composer analyse

License

The scripts and documentation in this project are released under the MIT License

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固