Files
gbdk-2020/docs/api/rand_8h.html
2024-05-13 22:45:19 -07:00

314 lines
17 KiB
HTML

<!-- HTML header for doxygen 1.8.14-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="cache-control" content="max-age=86400"/>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GBDK 2020 Docs: gbdk-lib/include/rand.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen_extra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">GBDK 2020 Docs
&#160;<span id="projectnumber">4.3.0</span>
</div>
<div id="projectbrief">API Documentation for GBDK 2020</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('rand_8h.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a> </div>
<div class="headertitle">
<div class="title">rand.h File Reference</div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;<a class="el" href="types_8h_source.html">types.h</a>&gt;</code><br />
<code>#include &lt;<a class="el" href="stdint_8h_source.html">stdint.h</a>&gt;</code><br />
</div>
<p><a href="rand_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a690f251553b39fd4f31894826141b61a"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a690f251553b39fd4f31894826141b61a">RAND_MAX</a>&#160;&#160;&#160;255</td></tr>
<tr class="separator:a690f251553b39fd4f31894826141b61a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6dbd2f1a15221db40f456cf574a793b4"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a6dbd2f1a15221db40f456cf574a793b4">RANDW_MAX</a>&#160;&#160;&#160;65535</td></tr>
<tr class="separator:a6dbd2f1a15221db40f456cf574a793b4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a964538799843c0ba5bd01151ef7e2640"><td class="memItemLeft" align="right" valign="top">void&#160;</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>
<tr class="separator:a964538799843c0ba5bd01151ef7e2640"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad080d802f20859660e0faf0199a8a674"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#ad080d802f20859660e0faf0199a8a674">rand</a> (void) <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr>
<tr class="separator:ad080d802f20859660e0faf0199a8a674"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4f32e90bdc46a5447d12fe96c3967f0a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a4f32e90bdc46a5447d12fe96c3967f0a">randw</a> (void) <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr>
<tr class="separator:a4f32e90bdc46a5447d12fe96c3967f0a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a333400f85febd7e1360835955103db8b"><td class="memItemLeft" align="right" valign="top">void&#160;</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>
<tr class="separator:a333400f85febd7e1360835955103db8b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af294ca742107f138a7e6f3be376ca53d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#af294ca742107f138a7e6f3be376ca53d">arand</a> (void) <a class="el" href="asm_2types_8h.html#a0971918860055db2e50dacea4da8f3bc">OLDCALL</a></td></tr>
<tr class="separator:af294ca742107f138a7e6f3be376ca53d"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a7aab2f4a234108a5eae48e0d26380ae7"><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="rand_8h.html#a7aab2f4a234108a5eae48e0d26380ae7">__rand_seed</a></td></tr>
<tr class="separator:a7aab2f4a234108a5eae48e0d26380ae7"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Random generator using the linear congruential method</p>
<dl class="section author"><dt>Author</dt><dd>Luc Van den Borre </dd></dl>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="a690f251553b39fd4f31894826141b61a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a690f251553b39fd4f31894826141b61a">&#9670;&nbsp;</a></span>RAND_MAX</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define RAND_MAX&#160;&#160;&#160;255</td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="a6dbd2f1a15221db40f456cf574a793b4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6dbd2f1a15221db40f456cf574a793b4">&#9670;&nbsp;</a></span>RANDW_MAX</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define RANDW_MAX&#160;&#160;&#160;65535</td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="a964538799843c0ba5bd01151ef7e2640"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a964538799843c0ba5bd01151ef7e2640">&#9670;&nbsp;</a></span>initrand()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void initrand </td>
<td>(</td>
<td class="paramtype"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a>&#160;</td>
<td class="paramname"><em>seed</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Initalise the pseudo-random number generator.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">seed</td><td>The value for initializing the random number generator.</td></tr>
</table>
</dd>
</dl>
<p>The seed should be different each time, otherwise the same pseudo-random sequence will be generated.</p>
<p>One way to do this is sampling (<a class="el" href="gb_2hardware_8h.html#afa1e18e47bf68ce68d7807fff6edf16b">DIV_REG</a>) up to 2 times (high byte of seed value then the low byte) at variable, non-deterministic points in time (such as when the player presses buttons on the title screen or in a menu).</p>
<p>It only needs to be called once to be initialized.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="rand_8h.html#ad080d802f20859660e0faf0199a8a674">rand()</a>, <a class="el" href="rand_8h.html#a4f32e90bdc46a5447d12fe96c3967f0a">randw()</a> </dd></dl>
</div>
</div>
<a id="ad080d802f20859660e0faf0199a8a674"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad080d802f20859660e0faf0199a8a674">&#9670;&nbsp;</a></span>rand()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> rand </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns a random byte (8 bit) value.</p>
<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#ad080d802f20859660e0faf0199a8a674">rand()</a> </p>
</div>
</div>
<a id="a4f32e90bdc46a5447d12fe96c3967f0a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4f32e90bdc46a5447d12fe96c3967f0a">&#9670;&nbsp;</a></span>randw()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> randw </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns a random word (16 bit) value.</p>
<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#ad080d802f20859660e0faf0199a8a674">rand()</a> </p>
</div>
</div>
<a id="a333400f85febd7e1360835955103db8b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a333400f85febd7e1360835955103db8b">&#9670;&nbsp;</a></span>initarand()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void initarand </td>
<td>(</td>
<td class="paramtype"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a>&#160;</td>
<td class="paramname"><em>seed</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Random generator using the linear lagged additive method</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">seed</td><td>The value for initializing the random number generator.</td></tr>
</table>
</dd>
</dl>
<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#ad080d802f20859660e0faf0199a8a674">rand()</a> to initialize the random generator.</p>
<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#af294ca742107f138a7e6f3be376ca53d">arand()</a> </dd></dl>
</div>
</div>
<a id="af294ca742107f138a7e6f3be376ca53d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af294ca742107f138a7e6f3be376ca53d">&#9670;&nbsp;</a></span>arand()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="stdint_8h.html#aba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> arand </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Returns a random number generated with the linear lagged additive method.</p>
<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#af294ca742107f138a7e6f3be376ca53d">arand()</a> </p>
</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
<a id="a7aab2f4a234108a5eae48e0d26380ae7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7aab2f4a234108a5eae48e0d26380ae7">&#9670;&nbsp;</a></span>__rand_seed</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="stdint_8h.html#adf4d876453337156dde61095e1f20223">uint16_t</a> __rand_seed</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">extern</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>The random number seed is stored in __rand_seed and can be saved and restored if needed.</p>
<div class="fragment"><div class="line"><span class="comment">// Save</span></div>
<div class="line">some_uint16 = <a class="code" href="rand_8h.html#a7aab2f4a234108a5eae48e0d26380ae7">__rand_seed</a>;</div>
<div class="line">...</div>
<div class="line"><span class="comment">// Restore</span></div>
<div class="line">__rand_seed = some_uint16;</div>
<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>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.14-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
</div>
</body>
</html>