Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MorphingDragon

macrumors 603
Original poster
Mar 27, 2009
5,159
6
The World Inbetween
How would you seed the random generator with a variable? All the examples on C I can find are using srandom(time(NULL)).

I had an idea for generating random numbers on an iPhone that I want to play around with, using the GPS Data, Time, and Accelerometer/Gyro Data. Because that would be very hard to get the same seed number twice.
 
This isn't for a program, this is for a CompSci essay.
Please just answer the question.

Wow, that was rude. If you don't provide all the information, don't expect people to assume that you know more than they do. Doing so on public forums is rude, and counter-productive to everyone's interest, including your own.
 
Wow, that was rude. If you don't provide all the information, don't expect people to assume that you know more than they do. Doing so on public forums is rude, and counter-productive to everyone's interest, including your own.

You'll have to excuse people, sometimes their squishy brains just want an answer.

]

Thanks.
 
This isn't for a program, this is for a CompSci essay.
Please just answer the question.

Then I would use srandomdev(), and not srandom().

And if I were somehow compelled beyond reason to use srandom(), then I would seed it with data read from arc4random().

I would then not call random() at all, because you didn't give that as a requirement. Instead, I would make the required seeding of srandom(), then call arc4random() to actually generate random numbers, because random() is weak and arc4random() is not.
 
Then I would use srandomdev(), and not srandom().

And if I were somehow compelled beyond reason to use srandom(), then I would seed it with data read from arc4random().

I would then not call random() at all, because you didn't give that as a requirement. Instead, I would make the required seeding of srandom(), then call arc4random() to actually generate random numbers, because random() is weak and arc4random() is not.

I know that arc4random() has a better pseudonumber algorithm. But I didn't know about srandomdev()

The essay isn't about generating numbers, its about coming up with a way to solve the random number problem without resorting to things like radiation. (And suitably backed up with things like physics/mathematics/CompSci theory and actual code snippets)

---

I'm sorry if I'm a bit snippy.
 
I know that arc4random() has a better pseudonumber algorithm. But I didn't know about srandomdev()
Step 1: Read the fine man page.

The essay isn't about generating numbers, its about coming up with a way to solve the random number problem without resorting to things like radiation. (And suitably backed up with things like physics/mathematics/CompSci theory and actual code snippets)

---

I'm sorry if I'm a bit snippy.
A few physical sources of entropy available to a typical computer:

Shot noise (google it).

Air turbulence in hard drives affects seek time.

Frequency jitter in oscillators.

Differences in arrival times of human-generated events (keystrokes, mousing, touches, etc.)

If all you can come up with is radiation, you're not trying very hard.

Be sure to look up shielding, too, because some sources can be biased by injecting RF externally, or even remotely.

As to combining the entropy for high-quality random numbers, see the Yarrow algorithm. If you don't know how it was developed, see Schneier's "Applied Cryptography" for the chapter on PRNGs. And google NIST hash competition.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.