Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /src/util/rand48.sml
ViewVC logotype

View of /src/util/rand48.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 228 - (download) (annotate)
Mon Sep 8 12:53:48 2008 UTC (11 years, 2 months ago) by jhr
File size: 1836 byte(s)
  Fix calling-convention attributes
(* rand48.sml
 *
 * COPYRIGHT (c) 2005 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * An SML wrapper around the rand48 calls supported by the C library.
 *)

signature RAND48 =
  sig

  (* a 48-bit seed value *)
    type seed

  (* create a new 48-bit seed value *)
    val new : (Word16.word *  Word16.word *  Word16.word) -> seed

  (* set the global seed *)
    val seed : seed -> unit

  (* random number generators that use the global seed (which will be modified) *)
    val drand : unit -> Real64.real	(* range [0, 1) *)
    val lrand : unit -> Int32.int	(* range [0, 2^31) *)
    val mrand : unit -> Int32.int	(* range [-2^31, 2^31) *)

  (* random number generators that use the given seed (which will be modified) *)
    val erand : seed -> Real64.real	(* range [0, 1) *)
    val nrand : seed -> Int32.int	(* range [0, 2^31) *)
    val jrand : seed -> Int32.int	(* range [-2^31, 2^31) *)

  end

structure Rand48 :> RAND48 =
  struct

    type seed = Word16.word array

  (* create a new 48-bit seed value *)
    fun new (a :  Word16.word, b, c) = let
	  val s = Array.array(3, a)
	  in
	    Array.update(s, 1, b);
	    Array.update(s, 2, c);
	    s
	  end

  (* set the global seed *)
    val seed = _import "seed48" stdcall : seed -> unit;

  (* random number generators that use the global seed (which will be modified) *)
    val drand = _import "drand48" stdcall : unit -> Real64.real;
    val lrand = _import "lrand48" stdcall : unit -> Int32.int;
    val mrand = _import "mrand48" stdcall : unit -> Int32.int;

  (* random number generators that use the given seed (which will be modified) *)
    val erand = _import "erand48" stdcall : seed -> Real64.real;
    val nrand = _import "nrand48" stdcall : seed -> Int32.int;
    val jrand = _import "jrand48" stdcall : seed -> Int32.int;

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0