Folks,

Thank you for lots of input on the random library.
If we can evolve a sensible proposal fast then we can put it 
in Haskell 98.

I propose that we discuss this among the people who have already
contributed, rather than saturate the main Haskell list further.
The union of contributors is in the header of this message.

So to contribute further, just reply to the long list in the to-field
of this message (I havn't created a proper new mailing list).  
Anyone else who wants to join in can send a message to that same list.

My own thoughts are below

Simon
==========================

  Think of a RandomSupply as a value from which one can generate a lot
  of pseudo random numbers.

        data RandomSupply = ... -- abstract

  A list of Ints is one concrete RandomSupply. So is a seed (such as 
  an Int or a pair of Ints).  But a RandomSupply should jolly well be
  abstract.

  If it's abstract, what operations should be provided?  Certainly things
  such as 

        newRandomSupply :: IO RandomSupply      
                -- Consult the Dow Jones and
                -- return an arbitrary supply

        mkRandomSupply :: Int -> RandomSupply
                -- Choose of of 2**31 pre-determined supplies
                -- or (equivalently) map an Int into a supply
                -- This is deterministic (of course) so you can
                -- get predictable random numbers

        mkRandom        :: RandomSupply -> Double       -- In range 0..1
        mkRandomInt     :: RandomSupply -> (Int,Int)         -> Int
        mkRandomInteger :: RandomSupply -> (Integer,Integer) -> Integer
        
        -- and perhaps plural forms
        mkRandoms        :: RandomSupply -> [Double]    -- In range 0..1
        mkRandomInts     :: RandomSupply -> (Int,Int)         -> [Int]
        mkRandomIntegers :: RandomSupply -> (Integer,Integer) -> [Integer]
        

        nextRandomSupply :: RandomSupply -> RandomSupply

  The interesting question is whether one should be able to split
  a supply
        
        splitRandomSupply :: RandomSupply -> (RandomSupply, RandomSupply)
  
  I do think this is useful: consider a program that recurses over a tree,
  and needs a random supply at the leaves. One can 'thread' the supply
  but that linearises the program; better to split it.

  
  All this is really very similar to Lennart's paper about conjuring
  up unique identifiers[1].


  So I have a question for the numerical people: can you implement
  splitRandomSupply?  It's easy to implement mkRandom/nextRandomSupply
  using the standard pseudo-random number generators.  But for split
  we need to transform a seed into *two* seeds.  The normal method
  cycles through a large number of seeds in a long cycle.  Generating
  two seeds means picking two points in this long cycle rather than
  just moving on one point at a time.

  If someone could produce a convincing implementation for the signature
  above I think it might do.

  Comments about both the design and the implementation welcomed.



  

[1]  Lennart Augustsson, Mikael Rittri, and Dan Synek. 
        Functional pearl: On generating unique names. 
        Journal of Functional Programming, 4(1):117-123, January 1994.


Reply via email to