--- /dev/null
+definition module Random
+
+ // Random number generator voor Linux gebruikers
+ // interface compatible met Random.dcl (helaas)
+ // -- mschool@science.ru.nl
+
+import StdFile
+
+:: RandomSeed
+
+// nullRandomSeed generates a fixed RandomSeed
+nullRandomSeed :: RandomSeed
+
+// GetNewRandomSeed generates a good RandomSeed, using /dev/urandom
+getNewRandomSeed :: !*env -> (!RandomSeed, !*env) | FileSystem env
+
+// Given a RandomSeed, Random generates a random number and a new RandomSeed.
+random :: !RandomSeed -> .(!Int, !RandomSeed)
+
--- /dev/null
+implementation module Random
+
+import StdFile, StdList, StdMisc, StdArray, Random
+
+:: RandomSeed :== Int
+
+nullRandomSeed :: RandomSeed
+nullRandomSeed = 0
+
+getNewRandomSeed :: !*env -> (!RandomSeed, !*env) | FileSystem env
+getNewRandomSeed env
+# (ok, src, env) = sfopen "/dev/urandom" FReadData env
+| not ok => abort "could not open /dev/urandom"
+# (bytes, src) = sfreads src 4
+ seed = foldl (\x y->(x<<8)+toInt y) 0 [c \\ c<-:bytes]
+| otherwise => (seed, env)
+
+random :: !RandomSeed -> .(!Int, !RandomSeed)
+random seed = (seed>>16 bitand 0xFFFF, seed*0x08088405+1)
+
--- /dev/null
+definition module RandomGetallen\r
+\r
+import Random\r
+\r
+random_n :: Int RandomSeed -> ([Int],RandomSeed)\r
+random_inf :: RandomSeed -> [Int]\r
+//shuffle :: [a] RandomSeed -> [a]\r
--- /dev/null
+implementation module RandomGetallen\r
+\r
+import StdEnv, Random\r
+\r
+//Start :: *World -> ([Int],*World)\r
+//Start world\r
+//# (rs,world) = getNewRandomSeed world\r
+//= (shuffle [1..10] rs,world)\r
+\r
+\r
+Start = shuffle [1..10] nullRandomSeed\r
+\r
+random_n :: Int RandomSeed -> ([Int],RandomSeed)\r
+random_n n seed = seqList (repeatn n random) seed\r
+\r
+random_inf :: RandomSeed -> [Int]\r
+random_inf seed = iterateSt random seed\r
+\r
+iterateSt :: (s -> (a,s)) s -> [a]\r
+iterateSt f s = [a : iterateSt f s`]\r
+where\r
+ (a,s`) = f s\r
+\r
+shuffle :: [a] RandomSeed -> [a]\r
+shuffle xs seed = (perms xs) !! ((fst (random seed)) rem (fac (length xs)))\r
+\r
+fac :: Int -> Int\r
+fac 0 = 1\r
+fac n = n * fac (n-1)\r
+\r
+perms :: [a] -> [[a]]\r
+perms [] = [[]]\r
+perms xs = [[xs!!i : xs`] \\ i <- [0..length xs - 1] , xs` <- perms (take i xs ++ drop (i+1) xs)]\r
--- /dev/null
+module ReturnEnBind\r
+\r
+import StdEnv, Random\r
+\r
+Start = 42\r
+\r
+(bind1) infix 0 :: (St s a) (a -> (St s b)) -> St s b\r
+//(bind1) infix 0 :: (s -> *(a,s)) (a -> (a -> *(a,s))) -> (s -> *(b,s))\r
+(bind1) f1 f2 = \st0 f2 (fst (f1 st0) (snd (f1 st0))\r
+// (r, st1) = f1 st0\r
+//(bind) f f2 :== \st0 -> let (r,st1) = f st0\r
+// in f2 r st1\r
+\r
+\r
+som2 :: (RandomSeed -> (Int,RandomSeed))\r
+som2 ...\r
+\r
+seqList1 :: [St s a] -> St s [a]\r
+seqList1 ...\r