• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rand() and srand() broken?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rand() and srand() broken?


  • Subject: Re: rand() and srand() broken?
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 25 Nov 2009 17:44:10 +0000

On 25 Nov 2009, at 17:26, Derek Gaston wrote:

> This is actually indicative of what we actually do in one of our applications (I know it doesn't usually make much sense to reseed all the time... but you're just going to have to trust me that it's necessary in our case ;-)

It's wrong.  Whether you think it's necessary or not, it's just plain wrong.  Pseudo-random number generators usually don't guarantee good output if you re-seed them all the time.

Perhaps you should explain the problem that you think requires reseeding every time and someone can help you to design your algorithm better?

You might also want to try the random() function rather than the rand() function, since it's usually a better generator.  I haven't looked to see whether that's true on OS X, but it normally has a better range and often uses a better algorithm behind the scenes too.

Kind regards,

Alastair.

--
http://alastairs-place.net



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >rand() and srand() broken? (From: Derek Gaston <email@hidden>)

  • Prev by Date: Re: [APPL:DarwinDev] rand() and srand() broken?
  • Next by Date: Re: rand() and srand() broken?
  • Previous by thread: Re: [APPL:DarwinDev] rand() and srand() broken?
  • Next by thread: Re: rand() and srand() broken?
  • Index(es):
    • Date
    • Thread