dimanche 24 juillet 2022

How do I generate a file of random IEEE-754 floats?

In a bash script, I want to generate a file containing IEEE-754 single-precision floating point values (i.e not a text file). I want them to have a uniform distribution over some range (which I have as string variables, $min_val and $max_val ; e.g. -100.0 and 200.0 respectively). I don't care that much about the "quality" of randomness, so anything passable to the naked human eye will do; and I don't want NaNs or infinities.

What's a convenient way to do that? I can't just user random characters from /dev/urandom and such.

Notes:

  • You may assume the minimum and maximum and not subnormal.
  • Other reasonable assumptions can be made, but please make them explicitly.



Aucun commentaire:

Enregistrer un commentaire