Page 1 of 1
Random numbers and combinations
Posted: Fri Aug 16, 2002 4:20 pm
by ccjob2
Hi,
I have to define a routine that extract some number (i.e. 9 numbers), into a range (i.e. from 2 to 65) and makes a combination of those numbers each (i.e.) 5 of all extract.
Is there some PHP functions that build that routine ? Or some scripts that you can indicate ?
If there is anyone that help me on that routine I thank very very much !!!
Thanks
Carlo

Posted: Fri Aug 16, 2002 4:33 pm
by gotDNS
The function
rand() will generate a random number (or at least one taken for computer clock ticks or w/e) between your parameter...such as:
That will get a random number between 1 and 20...very simple.....i suppose you could use that in like a loop, of do it 9 times

Posted: Fri Aug 16, 2002 4:50 pm
by hob_goblin
Code: Select all
srand((double) microtime() * 1000000);
$num = 0;
for($i = 0; $i < 5; $i++){
$num = $num + rand(2, 65);
}
Posted: Fri Aug 16, 2002 4:53 pm
by gotDNS
That works much better than doing it 9 times...lol......im just HORRIBLE with loops.....
The combination is the problem
Posted: Sat Aug 17, 2002 2:34 am
by ccjob2
Thanks for yours suggestions, but my problem is the combination of number series.
If I extract (i.e.) 30 numbers (random), I should combine all numbers and produce all available combinations of those numbers in groups of 5 numbers (i.e.) each.
For example:
Extraction: 3 56 4 55 22 33 44 78 90 43 2 .....
If I need to create groups of 5 numbers each, how many group may I create ? And which combinations ?
Example:
1th combination: 3 56 4 55 22
2nd combination: 3 56 4 55 33
3rd combination: 3 56 4 55 44
etc. etc.
To make that is there some routine already made on the net ?
Thanks for all !!!
Carlo