mardi 25 avril 2017

Issue with srand() (What is valid input to it? (Number of bits?))

I am having trouble using srand() to send a seed to rand().

The problem is that the routine (C, VS) takes an unsigned int, which to me means any input from 0 to 4.3 billion (or thereabouts).

I send it regularly an input which cycles rapidly from 0 to 4.3 billion. (Intel Time Stamp Cycle, masked to 32 bits).

What I am finding is that the srand() very often produced the same result for rand() despite my novel inputs. This is making me think that the seed should ACTUALLY be something less that 32 bits, and that my large value for some reason looks the same much of the time to the rand() function. I've looked over the source code for srand() and rand() and it is unclear why a large seed input would be problematic. I am looking for an explanation of what is going on and/or some documented recommendation for seed size for srand().




Aucun commentaire:

Enregistrer un commentaire