Debian Codegraph @

docs/manual/_randomImax_.html

raw
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>randomImax</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b>
12 randomImax
13 </b></font></table></table>
14 <p>A function that can be used in <a href="Formulas.html">Formulas</a>.</p>
15 <h2>Syntax and semantics</h2>
16 <dl>
17 <dt><b><code><font size=+1>randomImax</font></code></b> (<i><code><font size=+1>distribution#</font></code></i>)
18 <dd>sample from an array of relative probabilities.</dd>
19 </dl>
20 <h2>Example</h2>
21 <p>The following draws the outcome 1 one half of the time, the outcome 2 one sixth of the time, and the outcome 3 one third of the time:</p>
22 <code> for i to 20<br></code>
23 <code> outcome = <b>randomImax</b> ({ 3.0, 1.0, 2.0 })<br></code>
24 <code> <a href="_appendInfoLine_.html">appendInfoLine</a>: outcome<br></code>
25 <code> endfor<br></code>
26 <code style="color:red">=&gt;</code><br>
27 <code> 3<br></code>
28 <code> 1<br></code>
29 <code> 2<br></code>
30 <code> 2<br></code>
31 <code> 3<br></code>
32 <code> 2<br></code>
33 <code> 2<br></code>
34 <code> 1<br></code>
35 <code> 1<br></code>
36 <code> 3<br></code>
37 <code> 1<br></code>
38 <code> 1<br></code>
39 <code> 3<br></code>
40 <code> 1<br></code>
41 <code> 2<br></code>
42 <code> 1<br></code>
43 <code> 3<br></code>
44 <code> 1<br></code>
45 <code> 1<br></code>
46 <code> 1<br></code>
47 <p>All elements of the vector have to be non-negative:</p>
48 <code> <a href="_asserterror_.html">asserterror</a> Element 2 is less than zero; cannot interpret as a probability.<br></code>
49 <code> a = <b>randomImax</b> ({ 3.0, -1.0, 2.0 })<br></code>
50 <p>Some elements of the vector may be zero. The following draws the outcome 1 60 percent of the time, and the outcome 3 40 percent of the time:</p>
51 <code> for i to 20<br></code>
52 <code> outcome = <b>randomImax</b> ({ 3.0, 0.0, 2.0 })<br></code>
53 <code> <a href="_appendInfoLine_.html">appendInfoLine</a>: outcome<br></code>
54 <code> endfor<br></code>
55 <code style="color:red">=&gt;</code><br>
56 <code> 3<br></code>
57 <code> 1<br></code>
58 <code> 3<br></code>
59 <code> 3<br></code>
60 <code> 3<br></code>
61 <code> 1<br></code>
62 <code> 1<br></code>
63 <code> 1<br></code>
64 <code> 3<br></code>
65 <code> 1<br></code>
66 <code> 1<br></code>
67 <code> 3<br></code>
68 <code> 1<br></code>
69 <code> 1<br></code>
70 <code> 3<br></code>
71 <code> 3<br></code>
72 <code> 3<br></code>
73 <code> 1<br></code>
74 <code> 1<br></code>
75 <code> 1<br></code>
76 <p>Not all elements of the vector can be zero:</p>
77 <code> <a href="_asserterror_.html">asserterror</a> Cannot interpret a zero vector as probabilities.<br></code>
78 <code> a = <b>randomImax</b> ({ 0.0, 0.0, 0.0 })<br></code>
79 <h3>Links to this page</h3>
80 <ul>
81 <li><a href="Functions.html">Functions</a>
82 <li><a href="What_s_new_.html">What's new?</a>
83 </ul>
84 <hr>
85 <address>
86 <p>© Paul Boersma 2026</p>
87 </address>
88 </body>
89 </html>