<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>random number generator | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/random-number-generator/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 15 Oct 2020 12:52:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>random number generator | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>A better random number generator</title>
		<link>https://learncgames.com/a-better-random-number-generator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-better-random-number-generator</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 18 Oct 2020 23:00:48 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[random number generator]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1630</guid>

					<description><![CDATA[<p>How&#8217;s this for a minimal RNG implementation in C? // *Really* minimal PCG32 code / (c) 2014 M.E. O&#039;Neill / pcg-random.org // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t; uint32_t pcg32_random_r(pcg32_random_t* rng) { uint64_t oldstate = rng-&#62;state; // Advance internal state rng-&#62;state = [&#8230;]</p>
The post <a href="https://learncgames.com/a-better-random-number-generator/">A better random number generator</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:442,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/gdj-1086657\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3322478&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205100514\/https:\/\/pixabay.com\/users\/gdj-1086657\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 15:03:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 11:27:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 16:26:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 12:23:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-26 00:59:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 14:25:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-08 02:36:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 08:03:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 07:01:21&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 07:01:21&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:443,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3322478&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 15:03:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 11:27:58&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 16:26:41&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 12:23:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-26 00:59:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 14:25:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-08 02:36:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 08:03:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 07:01:21&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 07:01:21&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:444,&quot;href&quot;:&quot;https:\/\/www.pcg-random.org&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260124124227\/https:\/\/www.pcg-random.org\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 15:03:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 11:28:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 16:26:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-05 12:23:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 00:59:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-01 14:25:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 02:36:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 08:03:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 07:01:23&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 07:01:23&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:445,&quot;href&quot;:&quot;https:\/\/www.pcg-random.org\/party-tricks.html&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260111023456\/https:\/\/www.pcg-random.org\/party-tricks.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 15:03:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 11:28:00&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-02-28 16:26:44&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-05 12:23:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 00:59:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-01 14:25:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 02:36:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 08:03:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 07:01:23&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 07:01:23&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1631" aria-describedby="caption-attachment-1631" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-1631" src="https://learncgames.com/wp-content/uploads/2020/10/binary-3322478_640-300x187.png" alt="Binary numbers" width="300" height="187" srcset="https://learncgames.com/wp-content/uploads/2020/10/binary-3322478_640-300x187.png 300w, https://learncgames.com/wp-content/uploads/2020/10/binary-3322478_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1631" class="wp-caption-text">Image by <a href="https://pixabay.com/users/gdj-1086657/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3322478">Gordon Johnson</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3322478">Pixabay</a></figcaption></figure>
<p>How&#8217;s this for a minimal RNG implementation in C?</p>
<pre><code class="language-c" data-line="">// *Really* minimal PCG32 code / (c) 2014 M.E. O&#039;Neill / pcg-random.org
// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)

typedef struct { uint64_t state;  uint64_t inc; } pcg32_random_t;

uint32_t pcg32_random_r(pcg32_random_t* rng)
{
    uint64_t oldstate = rng-&gt;state;
    // Advance internal state
    rng-&gt;state = oldstate * 6364136223846793005ULL + (rng-&gt;inc|1);
    // Calculate output function (XSH RR), uses old state for max ILP
    uint32_t xorshifted = ((oldstate &gt;&gt; 18u) ^ oldstate) &gt;&gt; 27u;
    uint32_t rot = oldstate &gt;&gt; 59u;
    return (xorshifted &gt;&gt; rot) | (xorshifted &lt;&lt; ((-rot) &amp; 31));
}</code></pre>
<p><a title="Link to pcg-randopm.org" href="https://www.pcg-random.org/" target="_blank" rel="nofollow noopener noreferrer">https://www.pcg-random.org/</a></p>
<p>is a website dedicated to random numbers using their algorithms, The whole site is good but I particularly like the <a title="Link to party tricks page on pcg-random.org" href="https://www.pcg-random.org/party-tricks.html" target="_blank" rel="nofollow noopener noreferrer">party tricks page</a> where they show that one of their random number generators generates a sequence that contains interesting things like source of a C file, zip files and text from hamlet.</p>The post <a href="https://learncgames.com/a-better-random-number-generator/">A better random number generator</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1630</post-id>	</item>
	</channel>
</rss>
