src/Pure/library.ML
changeset 23922 707639e9497d
parent 23860 31f5c9e43e57
child 23932 7afee4bf89e8
equal deleted inserted replaced
23921:947152add153 23922:707639e9497d
   994   val a = 16807.0;
   994   val a = 16807.0;
   995   val m = 2147483647.0;
   995   val m = 2147483647.0;
   996   val random_seed = ref 1.0;
   996   val random_seed = ref 1.0;
   997 in
   997 in
   998 
   998 
   999 fun random () =
   999 fun random () = CRITICAL (fn () =>
  1000   let val r = rmod (a * !random_seed) m
  1000   let val r = rmod (a * ! random_seed) m
  1001   in (random_seed := r; r) end;
  1001   in (random_seed := r; r) end);
  1002 
  1002 
  1003 end;
  1003 end;
  1004 
  1004 
  1005 fun random_range l h =
  1005 fun random_range l h =
  1006   if h < l orelse l < 0 then raise RANDOM
  1006   if h < l orelse l < 0 then raise RANDOM
  1060 fun newid n = implode (map (fn i => Vector.sub (char_vec, i)) (radixpand (62, n)));
  1060 fun newid n = implode (map (fn i => Vector.sub (char_vec, i)) (radixpand (62, n)));
  1061 
  1061 
  1062 val gensym_seed = ref 0;
  1062 val gensym_seed = ref 0;
  1063 
  1063 
  1064 in
  1064 in
  1065   fun gensym pre = pre ^ newid (inc gensym_seed);
  1065   fun gensym pre = pre ^ newid (CRITICAL (fn () => inc gensym_seed));
  1066 end;
  1066 end;
  1067 
  1067 
  1068 
  1068 
  1069 (* stamps and serial numbers *)
  1069 (* stamps and serial numbers *)
  1070 
  1070 
  1071 type stamp = unit ref;
  1071 type stamp = unit ref;
  1072 val stamp: unit -> stamp = ref;
  1072 val stamp: unit -> stamp = ref;
  1073 
  1073 
  1074 type serial = int;
  1074 type serial = int;
  1075 local val count = ref 0
  1075 local val count = ref 0
  1076 in fun serial () = inc count end;
  1076 in fun serial () = CRITICAL (fn () => inc count) end;
  1077 
  1077 
  1078 val serial_string = string_of_int o serial;
  1078 val serial_string = string_of_int o serial;
  1079 
  1079 
  1080 
  1080 
  1081 (* generic objects *)
  1081 (* generic objects *)