Forum Moderators: coopster

Message Too Old, No Replies

complex random number generator

a lottery type random number generation problem

         

edjamaa

7:16 am on Aug 14, 2006 (gmt 0)

10+ Year Member



Hey guys.
would anyone know how to create random numbers eg one should be able to specify the range of numbers to be randomly generated eg from 9,10,11,12,...through to say 20.
the script should then pick and display say 6 numbers from the said range eg 9,19,11,10,12,13.

another function we could add to the script is the ability to pick numbers from a form and see if a user has 2 numbers matching the generated 3,4, etc
thanx

Tastatura

9:54 am on Aug 14, 2006 (gmt 0)

10+ Year Member



see this

[php.net...]

edjamaa

5:54 am on Aug 15, 2006 (gmt 0)

10+ Year Member



thanx for the link. but thats the simple part. what i find complex is making a function that will test the user data and test it aganist the randomized numbers and tell how many numbers that the user entered match the randomised.

thanx

FiRe

12:35 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



function randomer($lower, $upper, $how_many) {
$r = "";
for ($i = 1; $i <= $how_many; $i++) {
$r .= rand($lower, $upper) . "\n";
}
return $r;
}

edjamaa

10:10 am on Aug 16, 2006 (gmt 0)

10+ Year Member



ok lemme try this a different way.
so i have the 5 different sets of random numbers gen generated by the rand() function.

now user puts in his/her 5 numbers.

the function i want is one that will check the 5 numbers that the user has entered, then cross check it with the 5 numbers generated by the rand() function.

the function should also count how many numbers that the user entered, match with the pre-existing ones created by the system

i hope i was very clear.
you have all been very helpfull

Tastatura

5:09 pm on Aug 16, 2006 (gmt 0)

10+ Year Member



Hi,
I am not sure what else you need – you were already provided sample code that will generate set of random numbers, as well as a link to a random function description (and if you look around that site you will see that it’s a great reference for other PHP functions as well).
I seriously doubt that anyone on this forum will just write code for you – as I mentioned above, you were pointed in the right direction so you need to put a bit of an effort. Afterwards, if you run into problems, post your code (or part of your code) with specific question and I am sure someone here will help you out.

whoisgregg

7:19 pm on Aug 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you have an array of "winning" numbers and an array of "guessed" numbers and need to compare one array to the other?

Perhaps array_intersect [php.net] is the missing piece of the puzzle? :)

If not, surely one of the array functions will do the trick. I originally figured that array_search would do the trick, but array_intersect looks more elegant.

edjamaa

5:42 am on Aug 21, 2006 (gmt 0)

10+ Year Member



thanx guys. ps i didnt want someone to write the code for me. i just phrased my question wrongly and people showed me the part of the code that i had already done. :)