pixeloution/true-random

该软件包最新版本(1.0.0)没有可用的许可信息。

从random.org获取随机数据的接口

1.0.0 2013-07-21 03:53 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:45:18 UTC


README

Composer兼容库,用于与random.org的API交互,以生成真正随机的整数列表、整数序列和随机字母数字字符串。

random.org限制了您每天可以生成的随机数/字符串的数量,该程序将在发送请求之前检查您的剩余配额。如果您需要超过免费额度,可以在random.org找到购买额外的说明。

我与random.org没有任何关系,只是觉得它是一个很酷的服务。

安装

通过Packagist安装

"require" : 
{ 
  "pixeloution/true-random" : "*" 
},

在您的composer.json文件中

设置

use Pixeloution\Random\Randomizer;

# takes a partial User Agent as an argument; random.org requests you use your
# email address in case of issues
$generator = new Randomizer( 'name@example.com' );

生成整数列表

返回一个介于min和max之间的非唯一整数数组

$generator->integers( $minimum_value, $maximum_value, $quantity );

生成整数序列

返回一个从$start到$end的整数数组,每个整数只出现一次。

$generator->sequence( $start, $end );

生成随机字符串列表

返回一个长度为$length的字符串数组,由通过位操作选项指定的字符类型组成。默认值是ALL ^ UNIQUE

选项包括

  • Randomizer::DIGITS
  • Randomizer::UPPERCASE
  • Randomizer::LOWERCASE
  • Randomizer::UNIQUE
  • Randomizer::ALL

一些示例

# returns all strings containing uppercase and lowercase only
$generator->strings( $len, $qty, Randomizer::UPPERCASE | Randomizer::LOWERCASE );

# returns lowercase strings, no repeated letters
$generator->strings( $len, $qty, Randomizer::LOWERCASE | Randomizer::UNIQUE );

# returns uppercase, lowercase, numeric with non-unique charaters. this is the default
$generator->strings( $len, $qty, Randomizer::ALL ^ Randomizer::UNIQUE );