Question

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.

Was it helpful?

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.

OTHER TIPS

Thank you H2CO3. I also found some more info for anyone who looks up this question:

http://en.wikipedia.org/wiki/Interval_(mathematics)

parenthesis denote exclusion of the endpoint, and square brackets denote inclusion.

So if I want to exclude zero, but include 1: (0 < r <= 1)

I use:

r = dsfmt_gv_genrand_open_close()

which is (0,1]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top