<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.deltaworlds.com/index.php?action=history&amp;feed=atom&amp;title=Aw_random</id>
	<title>Aw random - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.deltaworlds.com/index.php?action=history&amp;feed=atom&amp;title=Aw_random"/>
	<link rel="alternate" type="text/html" href="https://wiki.deltaworlds.com/index.php?title=Aw_random&amp;action=history"/>
	<updated>2026-04-17T01:58:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.deltaworlds.com/index.php?title=Aw_random&amp;diff=198&amp;oldid=prev</id>
		<title>Xan: Created page with &quot;{{SDK added in|version=2.1|sdk=13|world=|universe=|browser=}}  __NOTOC__   int aw_random (void)  ==Description== Returns a random number.  ==Notes== The psuedo-random number generator (PRNG) employed by this method is [http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html Mersenne Twister] (MT) by Matsumoto and Nishimura. It sets new standards for the period, quality and speed of random number generators. The incredible period is 219937 - 1, a number with about 6000 d...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.deltaworlds.com/index.php?title=Aw_random&amp;diff=198&amp;oldid=prev"/>
		<updated>2025-04-07T19:26:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{SDK added in|version=2.1|sdk=13|world=|universe=|browser=}}  __NOTOC__   int aw_random (void)  ==Description== Returns a random number.  ==Notes== The psuedo-random number generator (PRNG) employed by this method is [http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html Mersenne Twister] (MT) by Matsumoto and Nishimura. It sets new standards for the period, quality and speed of random number generators. The incredible period is 219937 - 1, a number with about 6000 d...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{SDK added in|version=2.1|sdk=13|world=|universe=|browser=}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
 int aw_random (void)&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
Returns a random number.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
The psuedo-random number generator (PRNG) employed by this method is [http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html Mersenne Twister] (MT) by Matsumoto and Nishimura. It sets new standards for the period, quality and speed of random number generators. The incredible period is 219937 - 1, a number with about 6000 digits. The 32-bit random numbers exhibit best possible equidistribution properties in dimensions up to 623 and it&amp;#039;s very fast.&lt;br /&gt;
&lt;br /&gt;
===Predictability===&lt;br /&gt;
This PRNG is should &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; be used in cryptography as it has major vulnerabilities:&lt;br /&gt;
&lt;br /&gt;
*Observing a sufficiently long sequence of outputs from MT is enough to predict all future outputs.&lt;br /&gt;
*It takes many iterations before the initial non-random state produces output that will pass a randomness test.&lt;br /&gt;
&lt;br /&gt;
Two steps can be taken to mitigate the problems:&lt;br /&gt;
&lt;br /&gt;
*Generate multiple 32-bit outputs (e.g. 8 would be sufficient) and digest them using a [http://en.wikipedia.org/wiki/Cryptographic_hash_function cryptographic hash function] such as RIPEMD or SHA-1.&lt;br /&gt;
*Throw away the first x number of outputs from MT (e.g. call aw_random a million times when the SDK application is initialized).&lt;br /&gt;
&lt;br /&gt;
===Seed search attack===&lt;br /&gt;
The implementation used in the SDK is also vulnurable to a &amp;quot;seed search attack&amp;quot; due to only using a 32-bit number for the seed (i.e. it can only produce 2^32 different sequences of psedo-random numbers). This means that attackers would need to try at most 2^32 different seeds before finding the one being used.&lt;br /&gt;
&lt;br /&gt;
If a large number of initial outputs of MT have been thrown away then attackers would need to generate a longer sequence of numbers to test each seed. If 1,000,000 numbers were thrown away and 1000 have been passed to users then an attacker would need to generate roughly 1001000 * 2^32 numbers to be sure of finding the correct seed (in addition to seeding 2^32 times).&lt;br /&gt;
&lt;br /&gt;
==Arguments==&lt;br /&gt;
None&lt;br /&gt;
&lt;br /&gt;
==Argument attributes==&lt;br /&gt;
None&lt;br /&gt;
&lt;br /&gt;
==Return values==&lt;br /&gt;
Signed 32-bit number (i.e. a range of -2147483648 to +2147483647).&lt;br /&gt;
&lt;br /&gt;
==Returned attributes==&lt;br /&gt;
None&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&lt;br /&gt;
Naive&lt;br /&gt;
&lt;br /&gt;
 if ([[aw_random]] () == 547891)&lt;br /&gt;
   puts (&amp;quot;You sure are lucky&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Better&lt;br /&gt;
&lt;br /&gt;
 void random_init (void)&lt;br /&gt;
 {&lt;br /&gt;
   int i;&lt;br /&gt;
   &lt;br /&gt;
   for (i = 0; i &amp;lt; 1000000; i++)&lt;br /&gt;
     [[aw_random]] ();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 int random_secure (void)&lt;br /&gt;
 {&lt;br /&gt;
   int n;&lt;br /&gt;
   int i;&lt;br /&gt;
   &lt;br /&gt;
   n = 0;&lt;br /&gt;
   &lt;br /&gt;
   /*&lt;br /&gt;
     combine multiple outputs into a single number using xor&lt;br /&gt;
   */&lt;br /&gt;
   for (i = 0; i &amp;lt; 8; i++) &lt;br /&gt;
     n ^= [[aw_random]] ();&lt;br /&gt;
   &lt;br /&gt;
   return n;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 random_init (); &lt;br /&gt;
 &lt;br /&gt;
 if (random_secure () == 547891)&lt;br /&gt;
   puts (&amp;quot;You sure are lucky&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Secure&lt;br /&gt;
&lt;br /&gt;
 void random_init (void)&lt;br /&gt;
 {&lt;br /&gt;
   int i;&lt;br /&gt;
   &lt;br /&gt;
   for (i = 0; i &amp;lt; 1000000; i++)&lt;br /&gt;
     [[aw_random]] ();&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 int random_secure (void)&lt;br /&gt;
 {&lt;br /&gt;
   int buf[8];&lt;br /&gt;
   int i;&lt;br /&gt;
   &lt;br /&gt;
   for (i = 0; i &amp;lt; 8; i++) &lt;br /&gt;
     buf[i] = [[aw_random]] ();&lt;br /&gt;
   &lt;br /&gt;
   /*&lt;br /&gt;
     function that takes a buffer as input, digests it using RIPEMD-128&lt;br /&gt;
     and returns a 32-bit hash value from the output&lt;br /&gt;
   */&lt;br /&gt;
   &lt;br /&gt;
   return ripemd128_32 ((char*)&amp;amp;buf, sizeof (buf));&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 random_init (); &lt;br /&gt;
 &lt;br /&gt;
 if (random_secure () == 547891)&lt;br /&gt;
   puts (&amp;quot;You sure are lucky&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[aw_init]]&lt;br /&gt;
&lt;br /&gt;
[[Category: SDK Methods|R]]&lt;/div&gt;</summary>
		<author><name>Xan</name></author>
	</entry>
</feed>