[Haskell-cafe] random number generators
david karapetyan
dkarapetyan at ucdavis.edu
Thu Mar 22 15:38:47 EDT 2007
hi, i have been trying to learn haskell and i would like to translate the
following object-oriented pseudo-code into working haskell code but i'm
stumped on how to write the next function in the haskell code. any help is
appreciated.
class Random
...
end
ran = Random.new(300)
ran.next() <- this call generates a random number
ran.next() <- this one generates a different random number
so far what i have in haskell is:
data Random = Ran Int Int
next :: Random->Int <- i have no idea how to write the next function that
would give me the desired effect
because the object in the
object-oriented code can remember how many times 'next'
was called and i would like to
do the same for 'ran' in the haskell code.
ran = Ran 300 0
next ran <- this generates a random number
next ran <- this generates another random number but since
haskell is purely functional it is going to be the same
as from
the previous call of 'next' which is not what i want
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070322/dfe2a095/attachment.htm
More information about the Haskell-Cafe
mailing list