What to use when you need random values?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What to use when you need random values?

Silent Leaf
Hi,
I've had trouble finding the best way(s) to use random values in haskell, as it seems like there are several modules that either do the same thing or reuse one another i'm not sure. 

There is System.Random
- is it better to use the streams random(R)s or a more imperative randomRIO?
- is it better to use mkStdGen or newStdGen or getStdGen?
There is Test.QuickCheck and its type(class?) Gen
There is a module in Control.Monad (i think) which exports the type Rnd

What about performances, and all those options? What do you like to use with random numbers?

I know that's a lot of questions. feel free to only answer to a few of them. :)

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What to use when you need random values?

David McBride
When you are unsure about the differences between functions, it can be
good to read the haddocks for the library.

http://hackage.haskell.org/package/random-1.1/docs/System-Random.html

The standard haskell random library supports the idea of splitting a
seed randomly.  You take one seed and split it, and now you  have two
seeds, which will each generate different randoms independently.
getStdGen gets the current global seed.  newStdGen splits new a seed
off of the current global seed.  mkStdGen allows you to create a seed
from a value so that you can get the same set of randoms repeatedly.

I would say if you are in IO, just use randomRIO.  If you are in
monadic code that not IO at its base, you should use MonadRandom
library on hackage.  Quickcheck randomness is only really used in
quickcheck, although it is probably based off the standard libraries.

Just keep in mind that randomness is a concept that is a little hard
to wrap your head around in haskell until you've been using it a
little while.

On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf <[hidden email]> wrote:

> Hi,
> I've had trouble finding the best way(s) to use random values in haskell, as
> it seems like there are several modules that either do the same thing or
> reuse one another i'm not sure.
>
> There is System.Random
> - is it better to use the streams random(R)s or a more imperative randomRIO?
> - is it better to use mkStdGen or newStdGen or getStdGen?
> There is Test.QuickCheck and its type(class?) Gen
> There is a module in Control.Monad (i think) which exports the type Rnd
>
> What about performances, and all those options? What do you like to use with
> random numbers?
>
> I know that's a lot of questions. feel free to only answer to a few of them.
> :)
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What to use when you need random values?

Mike Houghton
This post is a useful discussion on randomness . Abstract Nonsense




On Friday, 23 June 2017, 16:11, David McBride <[hidden email]> wrote:


When you are unsure about the differences between functions, it can be
good to read the haddocks for the library.

http://hackage.haskell.org/package/random-1.1/docs/System-Random.html

The standard haskell random library supports the idea of splitting a
seed randomly.  You take one seed and split it, and now you  have two
seeds, which will each generate different randoms independently.
getStdGen gets the current global seed.  newStdGen splits new a seed
off of the current global seed.  mkStdGen allows you to create a seed
from a value so that you can get the same set of randoms repeatedly.

I would say if you are in IO, just use randomRIO.  If you are in
monadic code that not IO at its base, you should use MonadRandom
library on hackage.  Quickcheck randomness is only really used in
quickcheck, although it is probably based off the standard libraries.

Just keep in mind that randomness is a concept that is a little hard
to wrap your head around in haskell until you've been using it a
little while.

On Fri, Jun 23, 2017 at 10:24 AM, Silent Leaf <[hidden email]> wrote:

> Hi,
> I've had trouble finding the best way(s) to use random values in haskell, as
> it seems like there are several modules that either do the same thing or
> reuse one another i'm not sure.
>
> There is System.Random
> - is it better to use the streams random(R)s or a more imperative randomRIO?
> - is it better to use mkStdGen or newStdGen or getStdGen?
> There is Test.QuickCheck and its type(class?) Gen
> There is a module in Control.Monad (i think) which exports the type Rnd
>
> What about performances, and all those options? What do you like to use with
> random numbers?
>
> I know that's a lot of questions. feel free to only answer to a few of them.
> :)
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...