• 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: [APPL:DarwinDev] Re: rand() and srand() broken?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [APPL:DarwinDev] Re: rand() and srand() broken?


  • Subject: Re: [APPL:DarwinDev] Re: rand() and srand() broken?
  • From: Derek Gaston <email@hidden>
  • Date: Wed, 25 Nov 2009 12:15:35 -0700

On Nov 25, 2009, at 11:59 AM, Jay A. Kreibich wrote:

 This is, I suspect, part of the problem.  When random() replaced
 rand() in the BSD sources ages ago, I'm guessing nobody ever went
 back and made rand() better.  It was understood that you just didn't
 use rand() and "fixing" it by changing the algorithm would break
 applications like yours.

 This is less true in Linux.  For one thing, the source code has a
 much younger lineage, and I'm guessing someone decided it was a good
 idea to "improve" rand() at some point, even if that meant breaking
 backwards compatibility.

Have you tried you test on a BSD-based system?

I haven't.

Regardless, in that situation I'd write my own PRNG. That way you
can exactly control the balance between performance and quality and,
more importantly, you'll have cross-platform compatibility. From what
you're doing, you don't really need a "random" number, you just need
a good hash that will go from regular numbers (row/column) to a good
coverage of the number domain. Even something like a CRC might be a
good choice... unlike many crypto hashes, it does well with just a
few bytes of data to chew on.

Thanks for the idea of using a CRC... I hadn't thought about that. A random hash really is what we're going for here... and I'm starting to see that bastardizing rand/srand for that maybe wasn't the best idea ;-)


Derek
_______________________________________________
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>)
 >Re: rand() and srand() broken? (From: Jens Alfke <email@hidden>)
 >Re: [APPL:DarwinDev] Re: rand() and srand() broken? (From: "Jay A. Kreibich" <email@hidden>)

  • Prev by Date: Re: rand() and srand() broken?
  • Next by Date: Re: rand() and srand() broken?
  • Previous by thread: Re: [APPL:DarwinDev] Re: rand() and srand() broken?
  • Next by thread: kernel panic after time machine restore
  • Index(es):
    • Date
    • Thread