samedi 5 août 2017

In Java, is there a simple way to generate random N bits, but make sure that there is at least ONE bit equals 1 for all N bits?

As for N, it could be as large as 179.

For example, I was able to do it for n up to 32 bits:

new Random().nextInt(2^n-1)+1

nextLong() is not possible because I can't pass a value to it and it only generates a random value up to 48-bit.




Aucun commentaire:

Enregistrer un commentaire