jeudi 26 septembre 2019

How to specify a maximum value in Java's SecureRandom nextLong

In Java I wish to generate a randomly picked long number within an exclusive upper bound.

Normally if it were an Int I could do

int nextInt = new SecureRandom.nextInt(500);

Why can't I also do

long nextLong = new SecureRandom.nextLong(4294967296L);

Is there a work around to this?

Thanks




Aucun commentaire:

Enregistrer un commentaire