4 ms·
Excuse my ignorance, but what is the meaning of the differing brackets in the notation you're using: "[0,1)"?
by twobyfour 9y ago
Excuse my ignorance, but what is the meaning of the differing brackets in the notation you're using: "[0,1)"?
- ColinWright 9y agoStandard mathematical notation to indicate whether the endpoint is or is not included. { x : a < x && x < b } <=> (a,b) { x : a <=x && x < b } <=> [a,b) { x : a < x && x <=b } <=> (a,b] { x : a <=x && x <=b } <=> [a,b] In the example above the questioner is asking about getting a number in the range 1 to X inclusive. That would be [1,X]. Random number generators can return numbers in the range 0 to 1, including 0, not including 1. You can write that as [0,1). If you want an integer n in [1,X] and you get reals r [0,1), you can create a function: f : [0,1) -> [1,X], f(r) = 1+floor(X*r) Always check the endpoints, and the expected frequencies.
- twobyfour 9y agoThank you, that's helpful!