Added random, a global random object.
This commit is contained in:
parent
c8ca187af8
commit
a8844fe564
@ -41,6 +41,7 @@
|
||||
<li><a href="modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="modules/tango.html">tango</a></li>
|
||||
<li><a href="modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="modules/random.html">random</a></li>
|
||||
<li><a href="modules/log.html">log</a></li>
|
||||
<li><a href="modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="modules/textureutil.html">textureutil</a></li>
|
||||
@ -112,6 +113,11 @@
|
||||
<td class="summary">The DirectMapManipulator is similiar to the MapManipulator, except that it
|
||||
does not use the VoxelManip object, but the Minetest get_node/set_node
|
||||
functions.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="modules/random.html">random</a></td>
|
||||
<td class="summary">Random is a static utility that provides fast and easy access to
|
||||
random numbers.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="modules/log.html">log</a></td>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><strong>directmapmanipulator</strong></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -50,6 +50,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><strong>log</strong></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
282
doc/modules/random.html
Normal file
282
doc/modules/random.html
Normal file
@ -0,0 +1,282 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<head>
|
||||
<title>utils</title>
|
||||
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div id="product">
|
||||
<div id="product_logo"></div>
|
||||
<div id="product_name"><big><b></b></big></div>
|
||||
<div id="product_description"></div>
|
||||
</div> <!-- id="product" -->
|
||||
|
||||
|
||||
<div id="main">
|
||||
|
||||
|
||||
<!-- Menu -->
|
||||
|
||||
<div id="navigation">
|
||||
<br/>
|
||||
<h1>utils</h1>
|
||||
|
||||
<ul>
|
||||
<li><a href="../index.html">Index</a></li>
|
||||
</ul>
|
||||
|
||||
<h2>Contents</h2>
|
||||
<ul>
|
||||
<li><a href="#Functions">Functions</a></li>
|
||||
<li><a href="#Fields">Fields</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Modules</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><a href="../modules/interpolate.html">interpolate</a></li>
|
||||
<li><a href="../modules/tableutil.html">tableutil</a></li>
|
||||
<li><a href="../modules/stopwatch.html">stopwatch</a></li>
|
||||
<li><a href="../modules/facedirutil.html">facedirutil</a></li>
|
||||
<li><a href="../modules/posutil.html">posutil</a></li>
|
||||
<li><a href="../modules/pathutil.html">pathutil</a></li>
|
||||
<li><a href="../modules/inventoryutil.html">inventoryutil</a></li>
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><strong>random</strong></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
<li><a href="../modules/mapmanipulator.html">mapmanipulator</a></li>
|
||||
<li><a href="../modules/stringutil.html">stringutil</a></li>
|
||||
<li><a href="../modules/settings.html">settings</a></li>
|
||||
<li><a href="../modules/transform.html">transform</a></li>
|
||||
<li><a href="../modules/scheduler.html">scheduler</a></li>
|
||||
<li><a href="../modules/mathutil.html">mathutil</a></li>
|
||||
<li><a href="../modules/color.html">color</a></li>
|
||||
<li><a href="../modules/blockutil.html">blockutil</a></li>
|
||||
<li><a href="../modules/nodeutil.html">nodeutil</a></li>
|
||||
<li><a href="../modules/arrayutil.html">arrayutil</a></li>
|
||||
<li><a href="../modules/noisemanager.html">noisemanager</a></li>
|
||||
<li><a href="../modules/constants.html">constants</a></li>
|
||||
<li><a href="../modules/list.html">list</a></li>
|
||||
<li><a href="../modules/blockedcache.html">blockedcache</a></li>
|
||||
<li><a href="../modules/fisheryates.html">fisheryates</a></li>
|
||||
<li><a href="../modules/test.html">test</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<h1>Module <code>random</code></h1>
|
||||
<p>Random is a static utility that provides fast and easy access to
|
||||
random numbers.</p>
|
||||
<p></p>
|
||||
|
||||
|
||||
<h2><a href="#Functions">Functions</a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#init">init ()</a></td>
|
||||
<td class="summary">Initializes random.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#next_bool">next_bool (chance)</a></td>
|
||||
<td class="summary">Returns true or false based on the given chance.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#next_float">next_float (lower_bound, upper_bound, decimal_places)</a></td>
|
||||
<td class="summary">Returns a float between the given bounds.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#next_int">next_int (lower_bound, upper_bound)</a></td>
|
||||
<td class="summary">Returns an int between the given bounds.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a href="#Fields">Fields</a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#max">max</a></td>
|
||||
<td class="summary">The internal maximum value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#min">min</a></td>
|
||||
<td class="summary">The internal minimum value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#random_provider">random_provider</a></td>
|
||||
<td class="summary">The provider for random numbers.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<h2><a name="Functions"></a>Functions</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "init"></a>
|
||||
<strong>init ()</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Initializes random. Should not be called from the client.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "next_bool"></a>
|
||||
<strong>next_bool (chance)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Returns true or false based on the given chance.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">chance</span>
|
||||
Optional. The "one in chance" chance to get true, defaults
|
||||
to 2 (ans in "one in two").
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
true or false based in the given chance.
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "next_float"></a>
|
||||
<strong>next_float (lower_bound, upper_bound, decimal_places)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Returns a float between the given bounds.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">lower_bound</span>
|
||||
Optional. The lower bound (inclusive), defaults to 0.
|
||||
</li>
|
||||
<li><span class="parameter">upper_bound</span>
|
||||
Optional. The upper bound (exclusive), defaults to 1.
|
||||
</li>
|
||||
<li><span class="parameter">decimal_places</span>
|
||||
Optional. To how many decimal places the resulting
|
||||
float should be rounded.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
a float between the given bounds.
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "next_int"></a>
|
||||
<strong>next_int (lower_bound, upper_bound)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Returns an int between the given bounds.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">lower_bound</span>
|
||||
Optional. The lower bound (inclusive), defaults to
|
||||
random.min.
|
||||
</li>
|
||||
<li><span class="parameter">upper_bound</span>
|
||||
Optional. The upper bound (exclusive), defaults to
|
||||
random.max.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
a integer between the given bounds.
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<h2><a name="Fields"></a>Fields</h2>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "max"></a>
|
||||
<strong>max</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
The internal maximum value.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "min"></a>
|
||||
<strong>min</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
The internal minimum value.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "random_provider"></a>
|
||||
<strong>random_provider</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
The provider for random numbers.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
</div> <!-- id="content" -->
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.2</a></i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
</html>
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><strong>rotationutil</strong></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -44,6 +44,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><strong>tango</strong></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><strong>textureutil</strong></li>
|
||||
|
@ -48,6 +48,7 @@
|
||||
<li><a href="../modules/wallmountedutil.html">wallmountedutil</a></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -50,6 +50,7 @@
|
||||
<li><strong>wallmountedutil</strong></li>
|
||||
<li><a href="../modules/tango.html">tango</a></li>
|
||||
<li><a href="../modules/directmapmanipulator.html">directmapmanipulator</a></li>
|
||||
<li><a href="../modules/random.html">random</a></li>
|
||||
<li><a href="../modules/log.html">log</a></li>
|
||||
<li><a href="../modules/rotationutil.html">rotationutil</a></li>
|
||||
<li><a href="../modules/textureutil.html">textureutil</a></li>
|
||||
|
@ -49,6 +49,7 @@ dofile(base_path .. "/mathutil.lua")
|
||||
dofile(base_path .. "/nodeutil.lua")
|
||||
dofile(base_path .. "/pathutil.lua")
|
||||
dofile(base_path .. "/posutil.lua")
|
||||
dofile(base_path .. "/random.lua")
|
||||
dofile(base_path .. "/rotationutil.lua")
|
||||
dofile(base_path .. "/scheduler.lua")
|
||||
dofile(base_path .. "/settings.lua")
|
||||
|
113
mods/utils/random.lua
Normal file
113
mods/utils/random.lua
Normal file
@ -0,0 +1,113 @@
|
||||
--[[
|
||||
Copyright (c) 2015, Robert 'Bobby' Zenz
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
|
||||
--- Random is a static utility that provides fast and easy access to
|
||||
-- random numbers.
|
||||
random = {
|
||||
--- The internal maximum value.
|
||||
max = 2147483647,
|
||||
|
||||
--- The internal minimum value.
|
||||
min = 0,
|
||||
|
||||
--- The provider for random numbers.
|
||||
random_provider = nil
|
||||
}
|
||||
|
||||
|
||||
--- Initializes random. Should not be called from the client.
|
||||
function random.init()
|
||||
if PcgRandom ~= nil then
|
||||
random_provider = PcgRandom(os.time())
|
||||
else
|
||||
math.randomseed(os.time())
|
||||
|
||||
random_provider = {
|
||||
next = function(self, lower_bound, upper_bound)
|
||||
return math.abs(math.random(lower_bound, upper_bound - 1))
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns true or false based on the given chance.
|
||||
--
|
||||
-- @param chance Optional. The "one in chance" chance to get true, defaults
|
||||
-- to 2 (ans in "one in two").
|
||||
-- @return true or false based in the given chance.
|
||||
function random.next_bool(chance)
|
||||
chance = chance or 2
|
||||
|
||||
if chance <= 0 then
|
||||
return false
|
||||
elseif chance == 1 then
|
||||
return true
|
||||
end
|
||||
|
||||
return random.next_int(0, chance) == chance - 1
|
||||
end
|
||||
|
||||
--- Returns a float between the given bounds.
|
||||
--
|
||||
-- @param lower_bound Optional. The lower bound (inclusive), defaults to 0.
|
||||
-- @param upper_bound Optional. The upper bound (exclusive), defaults to 1.
|
||||
-- @param decimal_places Optional. To how many decimal places the resulting
|
||||
-- float should be rounded.
|
||||
-- @return a float between the given bounds.
|
||||
function random.next_float(lower_bound, upper_bound, decimal_places)
|
||||
lower_bound = lower_bound or 0
|
||||
upper_bound = upper_bound or 1.0
|
||||
|
||||
local value = random_provider:next(random.min, random.max + 1)
|
||||
value = (value - random.min) / (random.max - random.min)
|
||||
value = value * (upper_bound - lower_bound) + lower_bound
|
||||
|
||||
if decimal_places then
|
||||
value = mathutil.round(value, decimal_places)
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
|
||||
--- Returns an int between the given bounds.
|
||||
--
|
||||
-- @param lower_bound Optional. The lower bound (inclusive), defaults to
|
||||
-- random.min.
|
||||
-- @param upper_bound Optional. The upper bound (exclusive), defaults to
|
||||
-- random.max.
|
||||
-- @return a integer between the given bounds.
|
||||
function random.next_int(lower_bound, upper_bound)
|
||||
lower_bound = lower_bound or random.min
|
||||
upper_bound = upper_bound or random.max
|
||||
|
||||
return random_provider:next(lower_bound, upper_bound)
|
||||
end
|
||||
|
||||
|
||||
-- Initialize the random object.
|
||||
random.init()
|
||||
|
70
test/random.lua
Normal file
70
test/random.lua
Normal file
@ -0,0 +1,70 @@
|
||||
|
||||
-- Load the test file.
|
||||
dofile("./mods/utils/test.lua")
|
||||
|
||||
-- Load the file for testing.
|
||||
dofile("./mods/utils/random.lua")
|
||||
dofile("./mods/utils/mathutil.lua")
|
||||
dofile("./mods/utils/tableutil.lua")
|
||||
|
||||
|
||||
-- The following tests are neither perfect nor well formed,
|
||||
-- but they make sure the code is run and is kinda working.
|
||||
|
||||
|
||||
test.start("random")
|
||||
|
||||
|
||||
test.run("next_boolean", function()
|
||||
for counter = 0, 1000, 1 do
|
||||
test.equals(true, random.next_bool(1), "next_bool(1) returned false.")
|
||||
end
|
||||
|
||||
local trues = 0
|
||||
for counter = 0, 1000, 1 do
|
||||
if random.next_bool() then
|
||||
trues = trues + 1
|
||||
end
|
||||
end
|
||||
|
||||
test.equals(false, trues > 750, "next_bool() returned more than 3/4 (" .. trues .. ") as true.")
|
||||
test.equals(false, trues < 250, "next_bool() returned less than 1/4 (" .. trues .. ") as true.")
|
||||
|
||||
trues = 0
|
||||
for counter = 0, 1000, 1 do
|
||||
if random.next_bool(5) then
|
||||
trues = trues + 1
|
||||
end
|
||||
end
|
||||
|
||||
test.equals(false, trues > 250, "next_bool() returned more than 250 (" .. trues .. ") as true.")
|
||||
test.equals(false, trues < 50, "next_bool() returned less than 50 (" .. trues .. ") as true.")
|
||||
end)
|
||||
|
||||
test.run("next_float", function()
|
||||
for counter = 0, 1000, 1 do
|
||||
local value = random.next_float(0, 15)
|
||||
test.equals(true, mathutil.in_range(value, 0, 14.9999999999999), value .. " is not in range 0-14.999...")
|
||||
end
|
||||
for counter = 0, 1000, 1 do
|
||||
local value = random.next_float(0.25, 0.5)
|
||||
test.equals(true, mathutil.in_range(value, 0.25, 0.49999999999), value .. " is not in range 0.25-0.4999...")
|
||||
end
|
||||
|
||||
for counter = 0, 1000, 1 do
|
||||
local value = random.next_float(0, 1.0, 2)
|
||||
test.equals(value, mathutil.round(value, 2), value .. " has more than 2 decimal places.")
|
||||
end
|
||||
end)
|
||||
|
||||
test.run("next_int", function()
|
||||
for counter = 0, 1000, 1 do
|
||||
local value = random.next_int(0, 15)
|
||||
test.equals(true, mathutil.in_range(value, 0, 14), value .. " is not in range 0-14.")
|
||||
end
|
||||
for counter = 0, 1000, 1 do
|
||||
local value = random.next_int(15, 30)
|
||||
test.equals(true, mathutil.in_range(value, 15, 29), value .. " is not in range 15-29.")
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user