Search code examples
crandomfloating-pointprngmersenne-twister

using dSFMT for random float (0,1)


This project is in Obj-C for iphone. I'm using the double float version of sfmt available here: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT

After seeding dsmft with the current time, I'm calling:

r = dsfmt_gv_genrand_close_open()

to generate a random float between 0 and 1. There are also two other options, namely:

r = dsfmt_gv_genrand_open_close()
r = dsfmt_gv_genrand_open_open()

I know by the documents that the distinction is whether the 0 or 1 side is open or closed, and is shown mathematically: [0,1), (0,1], or (0,1).

But I don't know what this means, or which to use for my needs. I just want the most uniformly distributed float between 0 and 1.


Solution

  • [0, 1) means that the generated float may be 0, but never 1 (closed interval on the left, open interval on the right)

    (0, 1] means that the generated float may be 1, but never 0 (close interval on the right, open interval on the left)

    (0, 1) means the generated number cannot be 0 neither 1.

    Which one to choose? I assume the library is well-written so all of these three functions should return a uniformly distributed number. The exact function to choose depends entirely on what you are trying to accomplish.