I need to get a random number between 2^70 and 2^80. This piece of code is always giving me an even number. I have read a few other kind of similar questions and that is where I got this idea. This should get the number 2^70 and add it to Math.random() (which should be (0,1]) after that random number is multiplied by 2^80. Is this close to being correct?
private static BigDecimal getN_M() {
BigDecimal n = new BigDecimal(Math.pow(2, 70) + Math.random() * Math.pow(2, 80));
return n;
}
Aucun commentaire:
Enregistrer un commentaire