src/Tools/Metis/src/PortableSmlNJ.sml
changeset 25430 372d6749f00e
parent 24316 3880d21d6013
equal deleted inserted replaced
25429:9e14fbd43e6b 25430:372d6749f00e
    56 (* Critical section markup (multiprocessing)                                 *)
    56 (* Critical section markup (multiprocessing)                                 *)
    57 (* ------------------------------------------------------------------------- *)
    57 (* ------------------------------------------------------------------------- *)
    58 
    58 
    59 fun CRITICAL e = e ();     (*dummy*)
    59 fun CRITICAL e = e ();     (*dummy*)
    60 
    60 
       
    61 (* ------------------------------------------------------------------------- *)
       
    62 (* Generating random values.                                                 *)
       
    63 (* ------------------------------------------------------------------------- *)
       
    64 
       
    65 fun randomWord () = MLton.Random.rand ();
       
    66 
       
    67 fun randomBool () = Word.andb (randomWord (),0w1) = 0w0;
       
    68 
       
    69 fun randomInt 1 = 0
       
    70   | randomInt 2 = Word.toInt (Word.andb (randomWord (), 0w1))
       
    71   | randomInt 4 = Word.toInt (Word.andb (randomWord (), 0w3))
       
    72   | randomInt n = Word.toInt (Word.mod (randomWord (), Word.fromInt n));
       
    73 
       
    74 local
       
    75   fun wordToReal w = Real.fromInt (Word.toInt (Word.>> (w,0w1)))
       
    76 
       
    77   val normalizer = 1.0 / wordToReal (Word.notb 0w0);
       
    78 in
       
    79   fun randomReal () = normalizer * wordToReal (randomWord ());
       
    80 end;
       
    81 
    61 end
    82 end
    62 
    83 
    63 (* ------------------------------------------------------------------------- *)
    84 (* ------------------------------------------------------------------------- *)
    64 (* Quotations a la Moscow ML.                                                *)
    85 (* Quotations a la Moscow ML.                                                *)
    65 (* ------------------------------------------------------------------------- *)
    86 (* ------------------------------------------------------------------------- *)