GithubHelp home page GithubHelp logo

Random numbers about compiler HOT 5 CLOSED

elm avatar elm commented on May 21, 2024
Random numbers

from compiler.

Comments (5)

tinco avatar tinco commented on May 21, 2024
randomNumber = Random.inRange 1 10
main = lift (plainText . show) randomNumber

from compiler.

evancz avatar evancz commented on May 21, 2024

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

Does that clarify things?

from compiler.

tinco avatar tinco commented on May 21, 2024

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?

from compiler.

evancz avatar evancz commented on May 21, 2024

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.

from compiler.

drewlesueur avatar drewlesueur commented on May 21, 2024

Thank you

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.