The latest volume in the Game Programming Gems series, a valuable reference for game developers presents articles that cover a variety of topics, techniques, issues, and skills in the field of game programming, including general programming, artificial intelligence, mathematics and physics, graphics, networking and multiplayer, audio, and scripting and data-driven systems, along with a CD containing relevant code and demos. Original. (Intermediate)
What is a good random number generator to use for a game in C++?
My considerations are:
rand()in quite a lot of places, so any other generator had better be good to justify all the changes it would require.
I don't know much about this subject, so the only alternative I could come up with is the Mersenne Twister; does it satisfy all these requirements? Is there anything else that's better?
Edit: Mersenne Twister seems to be the consensus choice. But what about point #4? Is it really that much better than
Edit 2: Let me be a little clearer on point 2: There is no way for players to cheat by knowing the random numbers. Period. I want it random enough that people (at least those who understand randomness) can't complain about it, but I'm not worried about predictions. That's why I put speed as the top consideration.
Edit 3: I'm leaning toward the Marsaglia RNGs now, but I'd still like more input. Therefore, I'm setting up a bounty.
Edit 4: Just a note: I intend to accept an answer just before midnight UTC today (to avoid messing with someone's rep cap). So if you're thinking of answering, don't wait until the last minute!
Also, I like the looks of Marsaglia's XORshift generators. Does anyone have any input about them?
Mersenne Twister is very good, and it's fast as well. I used it in a game and it's not hard at all to implement or use.
On that WELL page I linked you to, the number is the period of the algorithm. That is, you can get 2^N - 1 numbers before it needs reseeding, where N is: 512, 1024, 19937, or 44497. Mersenne Twister has a period of N = 19937, or 2^19937 - 1. You'll see this is a very large number :)
In response to your edit, yes the Twister or WELL is that much better than rand(). Also, the old modulus trick harms the distribution of the numbers. Even more reason to use boost :)
I've been having fun rendering charts and graphs from co-ordinates lately, and I'm fascinated by using matrices to transform co-ordinate spaces.
I've been able to successfully scale and invert 2 dimensional co-ordinate spaces, but now my appetite is whetted. :)
Where can I go for clear, informative, (free), educational material on matrices, matrix math, especially as applies to 2 and 3 dimensional space?
Those are the information that I found. Some of them might be valuable to You:
I also encourage (I don't know if this is the right word, I am just learning English) You, to look for this kind of information in one of those books (though they are not free, but You can find large parts of older ones on Google Books):
Each of those has section about math gems - and there are lots of neat tricks there. Those books are worth every cent.
There are also GPU Programming gems, so You might try them too.
If I will find more, I will edit and add links here, but to be honest - I found those links in about 10 minutes of using google. World's most popular browser stores data about everything - and yes, "everything" means matrices too.