[Haskell-beginners] Re: [Haskell-cafe] Just how unsafe is unsafe
Peter Verswyvelen
bugfact at gmail.com
Thu Feb 5 17:47:28 EST 2009
Well, one could say that a truly random number function takes as input time
and some constant unique identifier (serial number) of the TRND device and
gives you the random value measured at that time by this device. Of course
this would mean the random value is not really random, since "the potential
creator of the universe" would have known the value already, but to all
humble beings living in the bubble, it would be Truly Random :)
Then the question is, is time a function? If so, is it discrete?
Okay, this is not Haskell anymore, this would become philosophy, and since a
good and smart friend of mine told me that nobody really knows what time is,
this is off topic. Sorry! :)
On Thu, Feb 5, 2009 at 11:31 PM, Jake McArthur <jake at pikewerks.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Peter Verswyvelen wrote:
> | I do have asked myself the question whether a "really random generating"
> | function could be regarded as "pure" somehow (actually would a true
> | random function still be a mathematical function?)
> |
> | E.g. the function would return a true (not pseudo) random number,
> | practically unpredictable (e.g. hardware assisted, using some physical
> | phenomenon, e.g. using atmospheric noise or something). So you surely
> | won't get referential transparency but since the function is really
> | random, this would be correct behavior?
>
> An informal definition of a function might be something like a black box
> that takes and input and produces an output, and for each possible
> input, the output must be the same. Taking this to be a function, there
> is really no such thing as a random function, and if there was, it
> wouldn't even need to be a function. (What would the input to it be?)
>
> If you wanted to mathematically represent a random number, it would, in
> most cases I can think of, best be represented as a free variable. In a
> program, such a free variable could be filled in by the runtime.
> Conveniently, (and by no coincidence) this is something the IO monad can
> provide for us! :)
>
> | Of course you could just put this random generator in the IO monad, but
> | certain algorithms- like Monte Carlo - intuitively don't seem to operate
> | in a IO monad to me.
>
> Why not?
>
> A Random monad might be more appropriate in this case anyway. Such a
> monad is a State monad that hold a random seed. Every time a random
> number is needed, the seed is passed to a deterministic psuedo-random
> number generator, and a new seed is put as the next state.
>
> If a truly random number is ever needed, either IO or unsafeInterleaveIO
> will be needed. The use of unsafeInterleaveIO would be a (rightly)
> controversial choice though.
>
> - - Jake
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkmLaK4ACgkQye5hVyvIUKk88QCfRksu7z80QmzgjUvmiyrzDDjl
> QnsAn1R5DHz2tJpWP3yb0+U+loyBdyCX
> =RIX9
> -----END PGP SIGNATURE-----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090205/c98379ee/attachment.htm
More information about the Beginners
mailing list