Php弱随机值生成器,用于重复值有用的情况

Php弱随机值生成器,用于重复值有用的情况,php,random,Php,Random,我正在生成用于前端的测试数据,并希望生成ages。目前,我使用Rand1100生成的年龄在18到100岁之间,如下所示: require_once 'vendor/autoload.php'; $faker = Faker\Factory::create(); $superstars = array("Adam Cole","Finn Balor","Pete Dunne","Jordan Devlin","Noam Dar"); $fan_favourite_superstar_name =

我正在生成用于前端的测试数据,并希望生成ages。目前,我使用Rand1100生成的年龄在18到100岁之间,如下所示:

require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();

$superstars = array("Adam Cole","Finn Balor","Pete Dunne","Jordan Devlin","Noam Dar");
$fan_favourite_superstar_name = $superstars[ mt_rand( 0, count($superstars) -1 ) ];

$cities = array("London","Manchester","Leeds","Bristol");
$fan_location = $cities[ mt_rand( 0, count($cities) -1 ) ];

$the_models = array("Iphone","Nokia","Huawei","Samsung");
$fan_phone_model = $the_models[ mt_rand( 0, count($the_models) -1 ) ];


$array = Array (
    "0" => Array (
        "id" => uniqid(),
        "fan_favourite_superstar_name" => $fan_favourite_superstar_name,
        "fan_location" => $fan_location,
        "fan_phone_model" => $fan_phone_model,
        "fan_name" => $faker->name,
        "fan_age" => rand(18,100),
        "fan_comments" => $faker->text,
        "fan_picture" => rand(1,500),
        "last_updated" => time() + rand(1,1000),
    ),

然而,我希望我的年龄能够重复,尽管不是完全重复。除了rand之外,是否有一个弱随机性生成器可以确保随机生成的年龄重复n次?

以下是一个函数,用于显示我的解决方案建议:

函数getAge$start=18、$end=100、$repeat=20{ $result=null; 静态$ages=数组; 如果空$ages{
对于$i=$start;$i@Andreas,这是一个输入错误,我已经编辑过。看看这将有助于获得更多的随机结果。等等,我只是再看一次。你想让它重复吗?重复多少次?你能再解释一下你所说的随机重复是什么意思吗?你想要相同的顺序X次,还是相同的一组值以不同的随机顺序X次,还是什么e?@ArSeN如果对于生成的值21,它应该在1到500的池中重复20次。选择重复的内容的机制应该由库或函数决定。诸如此类。因此,基本上你只需要一些随机的重复数据,而不关心是什么机制造成了重复?那么为什么不直接添加值呢一个随机的次数,然后将整个集合随机化?或者你是在问是否有库可以为你做到这一点?检查它。我想把输出降序排列,看看有哪些重复。我想你可以再添加一个静态数组来计算输出的重复数