vendredi 16 avril 2021

How can I intentionally create random floating point / decimal precision errors in java?

My goal is to generate random numbers that all have decimal precision errors.

Here are some examples of types of numbers I would like to generate:

1.8181818723678589
1.2727272510528564
0.444444477558136

Here are strategies I have tried.

parseFloat("4.01500000000000000001"); BigDecimal.valueOf(ThreadLocalRandom.current().nextFloat()).multiply(BigDecimal.valueOf(ThreadLocalRandom.current().nextFloat())).doubleValue();

None of the things I tried have created even a single number similar to that which I am looking for.




Aucun commentaire:

Enregistrer un commentaire