3

Had there been no System.Random class, how would have you generated a random number?

Are there any known algorithms or have you guys ever designed one?

3
  • 1
    @Dimitar: stackoverflow.com/questions/462219/xkcd-random-number Commented Aug 27, 2010 at 7:04
  • 1
    may be you should read this and try to create one solution Random number generation Commented Aug 27, 2010 at 7:06
  • The Mersenne Twister is a very good option (it has a large period). There are other available and sample code is available if you Google for them. These include Knuth Subtractive, RANLUX, Trustworthe and ZiffGFSR4, among others. Commented Aug 27, 2010 at 8:21

4 Answers 4

7

True random numbers can only be generated "outside" a computer, using radioactivity counts and such. Some VIA processors have hardware to do so.

Volume two of The Art of Computer Programming by Don Knuth spends a lot of time discussing exhaustively various pseudo-random number implementations from a mathematical background. Recommended reading.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 you can't get a real random number via any programming language.
Via any deterministic programming language. But many aren't, in fact. E.g. create two threads, and let them race to a mutex. You get less than one bit of entropy that way, but it is really random.
1

You can't really generate a truly random number with our current deterministic computers. There are, however, many different ways to generate pseudorandom numbers. See pseudorandom number generator on wikipedia for some information on the algorithms.

Comments

1

Take a look at the Mersenne Twister. I belive this is the same algorithm implemented by System.Random, it is very common non cryptographically secure PRNG with a good random distribution.

Comments

1

Like the other answers say, its not possible to generate true random numbers with a computer, but as for pseudo-random, one algorithm that I've used before is the Linear Congruential Generator, its simple and fast, but I'm sure there are much better alternatives.

Edit: Grammar

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.