lundi 20 juin 2016

Does casting random integers to short give a uniform distribution?

As the title explains, I am looking to generate a series of random short values. Because there is no Random.nextShort() function, the easiest way to do what I want seems to be to cast integers to short, using:

Random rand = new Random(int seed);
(short) rand.nextInt()

However, I don't fully understand how this casting takes place, and so I cannot be sure that the resulting short values would still be random. Is this the case? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire