Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upProblem with small values in Random.int on init #635
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mariosangiorgio
Jun 2, 2016
Contributor
As I mentioned on the StackOverflow answer, this behaviour is a bit odd but I am not sure if that's expected or not. What is happening is that, for this combination of parameters, there are quite big intervals of seeds that generate the same first value of the pseudo-random sequence.
It's worth noting that, if we exclude the first value, the sequence of the numbers produced look random enough.
I had another look at the implementation of the random number generator, comparing it both to the Haskell implementation and to the original paper. I found that one of the magic numbers might have a wrong value.
We have magicNum7 = 2137383399 but I think it should be magicNum7 = 2147483399. Updating it is not affecting this particular issue, but it's still worth amending the constant to the correct value.
|
As I mentioned on the StackOverflow answer, this behaviour is a bit odd but I am not sure if that's expected or not. What is happening is that, for this combination of parameters, there are quite big intervals of seeds that generate the same first value of the pseudo-random sequence. It's worth noting that, if we exclude the first value, the sequence of the numbers produced look random enough. I had another look at the implementation of the random number generator, comparing it both to the Haskell implementation and to the original paper. I found that one of the magic numbers might have a wrong value. We have |
mariosangiorgio
referenced this issue
Jun 2, 2016
Merged
Amended constant value used by the pseudo-random number generator #636
jvoigtlaender
referenced this issue
Jul 24, 2016
Closed
Nonrandom distribution of Random.generate #673
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Jul 25, 2016
Contributor
@PezzA, @mariosangiorgio, in case you are still wondering what the issue here is: It's not the "magic numbers" thing, it's the fact that the randome generator is seeded from the current time at program start. See https://github.com/elm-lang/core/issues/673 for more explanation.
|
@PezzA, @mariosangiorgio, in case you are still wondering what the issue here is: It's not the "magic numbers" thing, it's the fact that the randome generator is seeded from the current time at program start. See https://github.com/elm-lang/core/issues/673 for more explanation. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
closed this
Sep 22, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This will almost certainly be resolved by the new RNG. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
connec
Dec 17, 2016
I also encountered this working through the Random section in the guide.
I think it's interesting (though probably not valuable) to observe that if "Initialize the dice to a random value" was added as an exercise, it would probably have to be removed or else it would generate a lot of confusion.
connec
commented
Dec 17, 2016
|
I also encountered this working through the I think it's interesting (though probably not valuable) to observe that if "Initialize the dice to a random value" was added as an exercise, it would probably have to be removed or else it would generate a lot of confusion. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seethroughtrees
Jun 23, 2017
I've encountered this same issue. It seems if I use Random.Int with 3 or less. I will get repeated numbers in the same fashion as seen above. Anything over 3, and I get random as expected.
Like the above, this only occurs when triggered on init. Is there a workaround here?
I can create and provide an example to reproduce or versions if necessary.
seethroughtrees
commented
Jun 23, 2017
|
I've encountered this same issue. It seems if I use Random.Int with 3 or less. I will get repeated numbers in the same fashion as seen above. Anything over 3, and I get random as expected. Like the above, this only occurs when triggered on init. Is there a workaround here? I can create and provide an example to reproduce or versions if necessary. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jun 25, 2017
Contributor
BTW that new RNG is #778. Until it's merged and released, use my library linked just above.
|
BTW that new RNG is #778. Until it's merged and released, use my library linked just above. |
PezzA commentedJun 2, 2016
Raised this question on stack overflow and it was suggested to create a bug report here.
http://stackoverflow.com/questions/37522369/elm-random-number-on-init-strange-behaviour
I've been working through the examples here:
http://guide.elm-lang.org/architecture/effects/random.html
And what I'm trying to do with the dice is to get to generate a D6 when then component is created.
However if I use 1 6 as the random min max, I only get 1 different value per minute. This only happens on init, it's fine in the orig example where it a UI action.