mercredi 25 mars 2020

How to generate random numbers in C with an appropriate spacing?

I had to generate a given number of float random values in the range [1,10] for some code. However, due to some constraints, the spacing between the random numbers has to be at least dx(given).

I'm using code blocks. (float)rand()/(float)(RAND_MAX/(10)) generates random numbers in the range.

Now, to achieve the desired spacing as said earlier, any suggestions for a simple strategy easily implementable in C?




Aucun commentaire:

Enregistrer un commentaire