mardi 9 juin 2020

How to generate Random float number within some range with both endpoints exclusive (a, b) using Java? [duplicate]

I need to implement the optimal reservior sampling algorithm which needs a random number generator for range (0,1) both exclusive. However Java's Random.nextFloat() or nextDouble() is [0,1). Even though the probability to meet zero is very small, it's still wrong to directly use it. Therefore how to implement a random number generator withon (a, b) with both endpoints exclusive?




Aucun commentaire:

Enregistrer un commentaire