random numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

random numbers

Post by Luke »

what's the best way to generate a random number? rand isn't working very well... keeps giving me the same number.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rand() will only give you exact same set if you seed it with the exact same number each pass.. how are you using it?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: random numbers

Post by Chris Corbyn »

One armed space goat wrote:what's the best way to generate a random number? rand isn't working very well... keeps giving me the same number.
This made me laugh :lol: "isn't working very well..." .... "keeps giving the same number..." That's fairly random :P

Apologies for the useless input.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

LOL, everyone knows a computer can't generate a truly random number! Jeesh, don’t you need a Geiger counter for that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hawleyjr wrote:LOL, everyone knows a computer can't generate a truly random number! Jeesh, don’t you need a Geiger counter for that?
You say this in jest, there are actually many sources of excellent entropy available to "normal" computers. Although rarely tapped, one of the great ones is the thermal registers on "modern" processors. There are online sources of high entropy too.. however, software only solutions do not entirely exist (without some hardware support) so... 50/50.. :?
Post Reply