Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random numbers #72

Closed
drewlesueur opened this issue Jan 2, 2013 · 5 comments
Closed

Random numbers #72

drewlesueur opened this issue Jan 2, 2013 · 5 comments

Comments

@drewlesueur
Copy link

Can you give me an example of how to do display a random number on the screen?

(I know this is not an issue. I am just trying to understand)

-Thanks
Drew
480-840-5406

@tinco
Copy link
Contributor

tinco commented Jan 2, 2013

randomNumber = Random.inRange 1 10
main = lift (plainText . show) randomNumber

@evancz
Copy link
Member

evancz commented Jan 2, 2013

This is another example: http://elm-lang.org/edit/examples/Reactive/Randomize.elm

Does that clarify things?

@tinco
Copy link
Contributor

tinco commented Jan 2, 2013

But.. I have a question about random numbers too.

randomNumber = Random.inRange 1 10
secondRandomNumber = Random.inRange 1 10
thirdRandomNumber = randomNumber

together a b c = (show a) ++ " " ++ (show b) ++ " " ++ (show c)

main = lift plainText $ lift3 together randomNumber secondRandomNumber thirdRandomNumber

This code returns 7 1 7 for me, but shouldn't it return 7 7 7? Is there some magic difference between referring to a signal directly and through a function?

@evancz
Copy link
Member

evancz commented Jan 2, 2013

Random.randomize is a non-deterministic signal function, so given the same signal, it will produce different outputs. You can think of (Random.inRange 0 10) as an alias for (Random.randomize 0 10 (constant ())).

I am not sure if this is "bad" behavior, but I think it is okay. It does not have side-effects observable outside of the Elm RTS, so it does not limit any opportunities to prune unused signals.

@drewlesueur
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants