mardi 17 novembre 2020

Generate a random number of n bits length [duplicate]

I want to generate random number(k bit) from some range(0 to n). Lets say i want 4bit number but not higher than 14. Function then should generate number from range 8-13 (binary: 1000,1001, 1010, 1011, 1100, 1101). MSB is important here (should be 1). Could need some hint how to use here Math.random.




Aucun commentaire:

Enregistrer un commentaire