<?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>shuffledness | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/shuffledness/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 08:17:06 +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>shuffledness | 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>More thoughts on shuffledness</title>
		<link>https://learncgames.com/more-thoughts-on-shuffledness/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=more-thoughts-on-shuffledness</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 17 Oct 2020 23:00:44 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[shuffledness]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1623</guid>

					<description><![CDATA[<p>Thinking about what I said, it can&#8217;t be just about how far a card moves when shuffled but how much disordering occurs as well. If you shuffled the deck and discovered 7 cards in a sequence like 2,3,4,5,6 of hearts deep into the deck, they would have moved from near the top of the deck [&#8230;]</p>
The post <a href="https://learncgames.com/more-thoughts-on-shuffledness/">More thoughts on shuffledness</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;:446,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/hucklebarry-12671981\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5444926&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:447,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5444926&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:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 16:50:16&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-06 07:02:55&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 18:25:39&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 18:25:39&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1625" aria-describedby="caption-attachment-1625" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-1625" src="https://learncgames.com/wp-content/uploads/2020/10/cards-5444926_640-300x169.jpg" alt="Shuffling" width="300" height="169" srcset="https://learncgames.com/wp-content/uploads/2020/10/cards-5444926_640-300x169.jpg 300w, https://learncgames.com/wp-content/uploads/2020/10/cards-5444926_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1625" class="wp-caption-text">Image by <a href="https://pixabay.com/users/hucklebarry-12671981/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5444926">Hucklebarry</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5444926">Pixabay</a></figcaption></figure>
<p>Thinking about <a title="Link to previous blog entry on measuring shuffledness" href="https://learncgames.com/how-to-measure-how-shuffled-a-deck-of-cards-is/" target="_blank" rel="nofollow noopener noreferrer">what I said</a>, it can&#8217;t be just about how far a card moves when shuffled but how much disordering occurs as well. If you shuffled the deck and discovered 7 cards in a sequence like 2,3,4,5,6 of hearts deep into the deck, they would have moved from near the top of the deck (an &#8220;ordered deck&#8221; is A-K in Hearts, Clubs, Diamonds and Spades) then it probably wasn&#8217;t a very good shuffle.</p>
<p>One way to measure &#8220;disorder&#8221; is to subtract each card&#8217;s ordinal value from it&#8217;s successor and sum up the absolute value of them . Ordinal value is the value 0-51 where 0 = Ace Hearts, 1 = 2 Hearts and so on. In an ordered deck the sum of all these subtractions will be 51. In a well shuffled deck I would guess it might be something like 1352 (52 x 26). Absolute value is the abs(x) function of x which is always positive if x is negative.  abs(-8) = 8. abs(8) = 8.</p>
<p>So now for shuffledness we have two values. Displacement and disorder. If both are calculated as a value between 0 and 1 then multiplying them together might work as a measure of shuffledness.</p>
<p>Here&#8217;s a very simple example of calculating the value for disorder. So far the calculations have never got a total much above 900, and not near 1352. I&#8217;ll run a few experiments and see the range of values.</p>
<pre><code class="language-c" data-line="">// shuffledness.c : This measures how shuffled a deck of cards is
// cards are held as values 0-51 in a 52 int array.

#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int deck[52];
time_t t;

// Order the cards 0-51. 0 = Acew Hards,13 = Ace Clubs,26 = Ace of Diamonds and 51 = King of Spades
void InitDeck() {
	for (int i = 0; i &lt; 52; i++) {
		deck[i] = i;
	}
}

// Works on glovbal array deck and calculates a value for how displayed each card is
float CalcDisorder() {
	int total=0;
	for (int i = 1; i &lt; 52; i++) {
		total += abs(deck[i] - deck[i - 1]);
	}
	printf(&quot;Total = %d\n&quot;, total);
	return total / (52.0f * 26.0f);
}

// Shuffle a deck by swapping two random cards a specified number of times
void ShuffleDeck(int numtries) {
	int firstIndex, secondIndex;
	for (int i = 0; i &lt; numtries; i++) {
		do {
			firstIndex = rand() % 52;
			secondIndex = rand() % 52;
		}
		while (firstIndex == secondIndex);
		int value = deck[firstIndex];
		deck[firstIndex] = deck[secondIndex];
		deck[secondIndex] = value;
	}
}

int main() {
	/* Intializes random number generator */
	srand((unsigned)time(&amp;t));
	InitDeck();
	ShuffleDeck(1000);
	printf(&quot;CalcDisorder() == %f\n&quot;, CalcDisorder());
	return 0;
}</code></pre>
<p>That&#8217;s about 50 lines long. I&#8217;ll work on it and add the displacement calculation and try and get a maximum figure the the disorder calculation.</p>The post <a href="https://learncgames.com/more-thoughts-on-shuffledness/">More thoughts on shuffledness</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">1623</post-id>	</item>
	</channel>
</rss>
