rand_8h.html (16773B)
1<!-- HTML header for doxygen 1.8.14--> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4<head> 5<meta http-equiv="cache-control" content="max-age=86400"/> 6<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> 7<meta http-equiv="X-UA-Compatible" content="IE=9"/> 8<meta name="generator" content="Doxygen 1.8.20"/> 9<meta name="viewport" content="width=device-width, initial-scale=1"/> 10<title>GBDK 2020 Docs: rand.h File Reference</title> 11<link href="tabs.css" rel="stylesheet" type="text/css"/> 12<script type="text/javascript" src="jquery.js"></script> 13<script type="text/javascript" src="dynsections.js"></script> 14<link href="navtree.css" rel="stylesheet" type="text/css"/> 15<script type="text/javascript" src="resize.js"></script> 16<script type="text/javascript" src="navtreedata.js"></script> 17<script type="text/javascript" src="navtree.js"></script> 18<link href="search/search.css" rel="stylesheet" type="text/css"/> 19<script type="text/javascript" src="search/searchdata.js"></script> 20<script type="text/javascript" src="search/search.js"></script> 21<link href="doxygen.css" rel="stylesheet" type="text/css" /> 22<link href="doxygen_extra.css" rel="stylesheet" type="text/css"/> 23</head> 24<body> 25<div id="top"><!-- do not remove this div, it is closed by doxygen! --> 26<div id="titlearea"> 27<table cellspacing="0" cellpadding="0"> 28 <tbody> 29 <tr style="height: 56px;"> 30 <td id="projectalign" style="padding-left: 0.5em;"> 31 <div id="projectname">GBDK 2020 Docs 32  <span id="projectnumber">4.0.6</span> 33 </div> 34 <div id="projectbrief">API Documentation for GBDK 2020</div> 35 </td> 36 </tr> 37 </tbody> 38</table> 39</div> 40<!-- end header part --> 41<!-- Generated by Doxygen 1.8.20 --> 42<script type="text/javascript"> 43/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ 44var searchBox = new SearchBox("searchBox", "search",false,'Search'); 45/* @license-end */ 46</script> 47<script type="text/javascript" src="menudata.js"></script> 48<script type="text/javascript" src="menu.js"></script> 49<script type="text/javascript"> 50/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ 51$(function() { 52 initMenu('',true,false,'search.php','Search'); 53 $(document).ready(function() { init_search(); }); 54}); 55/* @license-end */</script> 56<div id="main-nav"></div> 57</div><!-- top --> 58<div id="side-nav" class="ui-resizable side-nav-resizable"> 59 <div id="nav-tree"> 60 <div id="nav-tree-contents"> 61 <div id="nav-sync" class="sync"></div> 62 </div> 63 </div> 64 <div id="splitbar" style="-moz-user-select:none;" 65 class="ui-resizable-handle"> 66 </div> 67</div> 68<script type="text/javascript"> 69/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ 70$(document).ready(function(){initNavTree('rand_8h.html',''); initResizable(); }); 71/* @license-end */ 72</script> 73<div id="doc-content"> 74<!-- window showing the filter options --> 75<div id="MSearchSelectWindow" 76 onmouseover="return searchBox.OnSearchSelectShow()" 77 onmouseout="return searchBox.OnSearchSelectHide()" 78 onkeydown="return searchBox.OnSearchSelectKey(event)"> 79</div> 80 81<!-- iframe showing the search results (closed by default) --> 82<div id="MSearchResultsWindow"> 83<iframe src="javascript:void(0)" frameborder="0" 84 name="MSearchResults" id="MSearchResults"> 85</iframe> 86</div> 87 88<div class="header"> 89 <div class="summary"> 90<a href="#define-members">Macros</a> | 91<a href="#func-members">Functions</a> | 92<a href="#var-members">Variables</a> </div> 93 <div class="headertitle"> 94<div class="title">rand.h File Reference</div> </div> 95</div><!--header--> 96<div class="contents"> 97<div class="textblock"><code>#include <<a class="el" href="types_8h_source.html">types.h</a>></code><br /> 98<code>#include <<a class="el" href="stdint_8h_source.html">stdint.h</a>></code><br /> 99</div> 100<p><a href="rand_8h_source.html">Go to the source code of this file.</a></p> 101<table class="memberdecls"> 102<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a> 103Macros</h2></td></tr> 104<tr class="memitem:a690f251553b39fd4f31894826141b61a"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a690f251553b39fd4f31894826141b61a">RAND_MAX</a>   255</td></tr> 105<tr class="separator:a690f251553b39fd4f31894826141b61a"><td class="memSeparator" colspan="2"> </td></tr> 106<tr class="memitem:a6dbd2f1a15221db40f456cf574a793b4"><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a6dbd2f1a15221db40f456cf574a793b4">RANDW_MAX</a>   65535</td></tr> 107<tr class="separator:a6dbd2f1a15221db40f456cf574a793b4"><td class="memSeparator" colspan="2"> </td></tr> 108</table><table class="memberdecls"> 109<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a> 110Functions</h2></td></tr> 111<tr class="memitem:a964538799843c0ba5bd01151ef7e2640"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a964538799843c0ba5bd01151ef7e2640">initrand</a> (<a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> seed) <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr> 112<tr class="separator:a964538799843c0ba5bd01151ef7e2640"><td class="memSeparator" colspan="2"> </td></tr> 113<tr class="memitem:a21e0cee33278952c044f27d02c0b0d1a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a21e0cee33278952c044f27d02c0b0d1a">rand</a> () <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr> 114<tr class="separator:a21e0cee33278952c044f27d02c0b0d1a"><td class="memSeparator" colspan="2"> </td></tr> 115<tr class="memitem:ac659150eb39aae2f523bef6554b19b77"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#ac659150eb39aae2f523bef6554b19b77">randw</a> () <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr> 116<tr class="separator:ac659150eb39aae2f523bef6554b19b77"><td class="memSeparator" colspan="2"> </td></tr> 117<tr class="memitem:a333400f85febd7e1360835955103db8b"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a333400f85febd7e1360835955103db8b">initarand</a> (<a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> seed) <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr> 118<tr class="separator:a333400f85febd7e1360835955103db8b"><td class="memSeparator" colspan="2"> </td></tr> 119<tr class="memitem:a67415330a1c7984e4537dac753306804"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a67415330a1c7984e4537dac753306804">arand</a> () <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr> 120<tr class="separator:a67415330a1c7984e4537dac753306804"><td class="memSeparator" colspan="2"> </td></tr> 121</table><table class="memberdecls"> 122<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a> 123Variables</h2></td></tr> 124<tr class="memitem:a7aab2f4a234108a5eae48e0d26380ae7"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a7aab2f4a234108a5eae48e0d26380ae7">__rand_seed</a></td></tr> 125<tr class="separator:a7aab2f4a234108a5eae48e0d26380ae7"><td class="memSeparator" colspan="2"> </td></tr> 126</table> 127<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2> 128<div class="textblock"><p>Random generator using the linear congruential method</p> 129<dl class="section author"><dt>Author</dt><dd>Luc Van den Borre </dd></dl> 130</div><h2 class="groupheader">Macro Definition Documentation</h2> 131<a id="a690f251553b39fd4f31894826141b61a"></a> 132<h2 class="memtitle"><span class="permalink"><a href="#a690f251553b39fd4f31894826141b61a">◆ </a></span>RAND_MAX</h2> 133 134<div class="memitem"> 135<div class="memproto"> 136 <table class="memname"> 137 <tr> 138 <td class="memname">#define RAND_MAX   255</td> 139 </tr> 140 </table> 141</div><div class="memdoc"> 142 143</div> 144</div> 145<a id="a6dbd2f1a15221db40f456cf574a793b4"></a> 146<h2 class="memtitle"><span class="permalink"><a href="#a6dbd2f1a15221db40f456cf574a793b4">◆ </a></span>RANDW_MAX</h2> 147 148<div class="memitem"> 149<div class="memproto"> 150 <table class="memname"> 151 <tr> 152 <td class="memname">#define RANDW_MAX   65535</td> 153 </tr> 154 </table> 155</div><div class="memdoc"> 156 157</div> 158</div> 159<h2 class="groupheader">Function Documentation</h2> 160<a id="a964538799843c0ba5bd01151ef7e2640"></a> 161<h2 class="memtitle"><span class="permalink"><a href="#a964538799843c0ba5bd01151ef7e2640">◆ </a></span>initrand()</h2> 162 163<div class="memitem"> 164<div class="memproto"> 165 <table class="memname"> 166 <tr> 167 <td class="memname">void initrand </td> 168 <td>(</td> 169 <td class="paramtype"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> </td> 170 <td class="paramname"><em>seed</em></td><td>)</td> 171 <td></td> 172 </tr> 173 </table> 174</div><div class="memdoc"> 175<p>Initalise the pseudo-random number generator.</p> 176<dl class="params"><dt>Parameters</dt><dd> 177 <table class="params"> 178 <tr><td class="paramname">seed</td><td>The value for initializing the random number generator.</td></tr> 179 </table> 180 </dd> 181</dl> 182<p>The seed should be different each time, otherwise the same pseudo-random sequence will be generated.</p> 183<p>The DIV Register (<a class="el" href="gb_2hardware_8h.html#afa1e18e47bf68ce68d7807fff6edf16b">DIV_REG</a>) is sometimes used as a seed, particularly if read at some variable point in time (such as when the player presses a button).</p> 184<p>Only needs to be called once to initialize, but may be called again to re-initialize with the same or a different seed.</p> 185<dl class="section see"><dt>See also</dt><dd><a class="el" href="rand_8h.html#a21e0cee33278952c044f27d02c0b0d1a">rand()</a>, <a class="el" href="rand_8h.html#ac659150eb39aae2f523bef6554b19b77">randw()</a> </dd></dl> 186 187</div> 188</div> 189<a id="a21e0cee33278952c044f27d02c0b0d1a"></a> 190<h2 class="memtitle"><span class="permalink"><a href="#a21e0cee33278952c044f27d02c0b0d1a">◆ </a></span>rand()</h2> 191 192<div class="memitem"> 193<div class="memproto"> 194 <table class="memname"> 195 <tr> 196 <td class="memname"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> rand </td> 197 <td>(</td> 198 <td class="paramname"></td><td>)</td> 199 <td></td> 200 </tr> 201 </table> 202</div><div class="memdoc"> 203<p>Returns a random byte (8 bit) value.</p> 204<p><a class="el" href="rand_8h.html#a964538799843c0ba5bd01151ef7e2640">initrand()</a> should be used to initialize the random number generator before using <a class="el" href="rand_8h.html#a21e0cee33278952c044f27d02c0b0d1a">rand()</a> </p> 205 206</div> 207</div> 208<a id="ac659150eb39aae2f523bef6554b19b77"></a> 209<h2 class="memtitle"><span class="permalink"><a href="#ac659150eb39aae2f523bef6554b19b77">◆ </a></span>randw()</h2> 210 211<div class="memitem"> 212<div class="memproto"> 213 <table class="memname"> 214 <tr> 215 <td class="memname"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> randw </td> 216 <td>(</td> 217 <td class="paramname"></td><td>)</td> 218 <td></td> 219 </tr> 220 </table> 221</div><div class="memdoc"> 222<p>Returns a random word (16 bit) value.</p> 223<p><a class="el" href="rand_8h.html#a964538799843c0ba5bd01151ef7e2640">initrand()</a> should be used to initialize the random number generator before using <a class="el" href="rand_8h.html#a21e0cee33278952c044f27d02c0b0d1a">rand()</a> </p> 224 225</div> 226</div> 227<a id="a333400f85febd7e1360835955103db8b"></a> 228<h2 class="memtitle"><span class="permalink"><a href="#a333400f85febd7e1360835955103db8b">◆ </a></span>initarand()</h2> 229 230<div class="memitem"> 231<div class="memproto"> 232 <table class="memname"> 233 <tr> 234 <td class="memname">void initarand </td> 235 <td>(</td> 236 <td class="paramtype"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> </td> 237 <td class="paramname"><em>seed</em></td><td>)</td> 238 <td></td> 239 </tr> 240 </table> 241</div><div class="memdoc"> 242<p>Random generator using the linear lagged additive method</p> 243<dl class="params"><dt>Parameters</dt><dd> 244 <table class="params"> 245 <tr><td class="paramname">seed</td><td>The value for initializing the random number generator.</td></tr> 246 </table> 247 </dd> 248</dl> 249<p>Note: <a class="el" href="rand_8h.html#a333400f85febd7e1360835955103db8b">initarand()</a> calls <a class="el" href="rand_8h.html#a964538799843c0ba5bd01151ef7e2640">initrand()</a> with the same seed value, and uses <a class="el" href="rand_8h.html#a21e0cee33278952c044f27d02c0b0d1a">rand()</a> to initialize the random generator.</p> 250<dl class="section see"><dt>See also</dt><dd><a class="el" href="rand_8h.html#a964538799843c0ba5bd01151ef7e2640">initrand()</a> for suggestions about seed values, <a class="el" href="rand_8h.html#a67415330a1c7984e4537dac753306804">arand()</a> </dd></dl> 251 252</div> 253</div> 254<a id="a67415330a1c7984e4537dac753306804"></a> 255<h2 class="memtitle"><span class="permalink"><a href="#a67415330a1c7984e4537dac753306804">◆ </a></span>arand()</h2> 256 257<div class="memitem"> 258<div class="memproto"> 259 <table class="memname"> 260 <tr> 261 <td class="memname"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> arand </td> 262 <td>(</td> 263 <td class="paramname"></td><td>)</td> 264 <td></td> 265 </tr> 266 </table> 267</div><div class="memdoc"> 268<p>Returns a random number generated with the linear lagged additive method.</p> 269<p><a class="el" href="rand_8h.html#a333400f85febd7e1360835955103db8b">initarand()</a> should be used to initialize the random number generator before using <a class="el" href="rand_8h.html#a67415330a1c7984e4537dac753306804">arand()</a> </p> 270 271</div> 272</div> 273<h2 class="groupheader">Variable Documentation</h2> 274<a id="a7aab2f4a234108a5eae48e0d26380ae7"></a> 275<h2 class="memtitle"><span class="permalink"><a href="#a7aab2f4a234108a5eae48e0d26380ae7">◆ </a></span>__rand_seed</h2> 276 277<div class="memitem"> 278<div class="memproto"> 279<table class="mlabels"> 280 <tr> 281 <td class="mlabels-left"> 282 <table class="memname"> 283 <tr> 284 <td class="memname"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> __rand_seed</td> 285 </tr> 286 </table> 287 </td> 288 <td class="mlabels-right"> 289<span class="mlabels"><span class="mlabel">extern</span></span> </td> 290 </tr> 291</table> 292</div><div class="memdoc"> 293<p>The random number seed is stored in __rand_seed and can be saved and restored if needed.</p> 294<div class="fragment"><div class="line"><span class="comment">// Save</span></div> 295<div class="line">some_uint16 = <a class="code" href="rand_8h.html#a7aab2f4a234108a5eae48e0d26380ae7">__rand_seed</a>;</div> 296<div class="line">...</div> 297<div class="line"><span class="comment">// Restore</span></div> 298<div class="line">__rand_seed = some_uint16;</div> 299</div><!-- fragment --> 300</div> 301</div> 302</div><!-- contents --> 303</div><!-- doc-content --> 304<div class="ttc" id="arand_8h_html_a7aab2f4a234108a5eae48e0d26380ae7"><div class="ttname"><a href="rand_8h.html#a7aab2f4a234108a5eae48e0d26380ae7">__rand_seed</a></div><div class="ttdeci">uint16_t __rand_seed</div></div> 305<!-- HTML footer for doxygen 1.8.14--> 306<!-- start footer part --> 307<div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> 308</div> 309</body> 310</html>