1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>random</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>random</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
random
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Pseudo random number generation
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>Random number generator. The method is attributed to
B.A. Wichmann and I.D.Hill, in 'An efficient and portable
pseudo-random number generator', Journal of Applied
Statistics. AS183. 1982. Also Byte March 1987.
<P>The current algorithm is a modification of the version attributed
to Richard A O'Keefe in the standard Prolog library.
<P>Every time a random number is requested, a state is used to calculate
it, and a new state produced. The state can either be implicit (kept
in the process dictionary) or be an explicit argument and return value.
In this implementation, the state (the type <CODE>ran()</CODE>) consists of a
tuple of three integers.
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="seed/0"><STRONG><CODE>seed() -> ran()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Seeds random number generation with default (fixed) values
in the process dictionary, and returns the old state.
</DIV>
<P><A NAME="seed/3"><STRONG><CODE>seed(A1, A2, A3) -> ran()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>A1 = A2 = A3 = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Seeds random number generation with integer values in the process
dictionary, and returns the old state.
</DIV>
<P><A NAME="seed0/0"><STRONG><CODE>seed0() -> ran()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Returns the default state.
</DIV>
<P><A NAME="uniform/0"><STRONG><CODE>uniform()-> float()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Returns a random float uniformly distributed between <CODE>0.0</CODE>
and <CODE>1.0</CODE>, updating the state in the process dictionary.
</DIV>
<P><A NAME="uniform/1"><STRONG><CODE>uniform(N) -> int()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>N = int()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Given an integer <CODE>N >= 1</CODE>, <CODE>uniform/1</CODE> returns a
random integer uniformly distributed between <CODE>1</CODE> and
<CODE>N</CODE>, updating the state in the process dictionary.
</DIV>
<P><A NAME="uniform_s/1"><STRONG><CODE>uniform_s(State0) -> {float(), State1}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>State0 = State1 = ran()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Given a state, <CODE>uniform_s/1</CODE>returns a random float uniformly
distributed between <CODE>0.0</CODE> and <CODE>1.0</CODE>, and a new state.
</DIV>
<P><A NAME="uniform_s/2"><STRONG><CODE>uniform_s(N, State0) -> {int(), State1}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>N = int()</CODE></STRONG><BR>
<STRONG><CODE>State0 = State1 = ran()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Given an integer <CODE>N >= 1</CODE> and a state, <CODE>uniform_s/2</CODE>
returns a random integer uniformly distributed between <CODE>1</CODE> and
<CODE>N</CODE>, and a new state.
</DIV>
<H3>Note</H3>
<DIV CLASS=REFBODY>
<P>Some of the functions use the process dictionary variable
<CODE>random_seed</CODE> to remember the current seed.
<P> If a process calls <CODE>uniform/0</CODE> or <CODE>uniform/1</CODE> without
setting a seed first, <CODE>seed/0</CODE> is called automatically.
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Joe Armstrong - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|