Hello, I created a small simple script that generates a sequence of numbers and I would like to put a (hidden) list of numbers as the starting script, and I would like the script to detect if there is the same sequence of numbers than in the list, and if so, the script reset until it’s good
It’s for my school, and I’m having trouble
Hard to help without the actual problems/errors/code.
Yep, I have that :
<?php
$regularNumbers = 5;
$bonusNumbers = 1;
$regularNumbersMin = 1;
$regularNumbersMax = 69;
$bonusNumbersMin = 1;
$bonusNumbersMax = 26;
$bonusUniqueFromRegular = false;
$results = array(
'regular_nums' => array(),
'bonus_nums' => array()
);
foreach(range(1, $regularNumbers) as $i){
$randNum = mt_rand($regularNumbersMin, $regularNumbersMax);
while(in_array($randNum, $results['regular_nums'])){
$randNum = mt_rand($regularNumbersMin, $regularNumbersMax);
}
array_push($results['regular_nums'], $randNum);
}
foreach(range(1, $bonusNumbers) as $i){
$randNum = mt_rand($bonusNumbersMin, $bonusNumbersMax);
while(in_array($randNum, $results['bonus_nums']) || ($bonusUniqueFromRegular && in_array($randNum, $results['regular_nums']))){
$randNum = mt_rand($bonusNumbersMin, $bonusNumbersMax);
}
array_push($results['bonus_nums'], $randNum);
}
sort($results['regular_nums']);
sort($results['bonus_nums']);
echo 'Results: <br>';
echo implode(", ", $results['regular_nums']);
echo '<br>';
echo 'Bonus: <br>';
echo implode(", ", $results['bonus_nums']);
Hard to help without the actual problems/errors/…
If you want to check lists on equality you can just use the equals-operator
var_dump($list1 === $list2);