 |
Mycket flitig postare
|
|
Reg.datum: Jan 2003
Inlägg: 935
|
|
Mycket flitig postare
Reg.datum: Jan 2003
Inlägg: 935
|
Jag ska få fram fem olika tal mellan 1 och 29. Dvs ett tal får inte förekomma två gånger.
Använder nu följande metod. Men den känns lite krånglig. Finns det någon bättre variant?
$first = rand(1,29);
do {
$second = rand(1,29);
} while($first==$second);
do {
$third = rand(1,29);
} while($third==$first || $third==$second);
do {
$fourth = rand(1,29);
} while($fourth==$first || $fourth==$second || $fourth==$third);
do {
$fifth = rand(1,29);
} while($fifth==$first || $fifth==$second || $fifth==$third || $fifth==$fourth);
|