<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Gor Grigoryan - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Gor Grigoryan - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 16:29:52 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/gor8808/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Effectively Manage Unique Identifiers at Scale: From GUIDs to Snowflake IDs and Other Modern Solutions ]]>
                </title>
                <description>
                    <![CDATA[ What Are Unique Identifiers? 🪪 Unique identifiers (UIDs) are crucial components in software engineering and data management. They serve as distinct references for entities within a system and ensure that each item – whether a database record, a user... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-effectively-manage-unique-identifiers-at-scale/</link>
                <guid isPermaLink="false">66c4dea5fd5e7dd1b40d4a81</guid>
                
                    <category>
                        <![CDATA[ scalability ]]>
                    </category>
                
                    <category>
                        <![CDATA[ design patterns ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unique identifier ]]>
                    </category>
                
                    <category>
                        <![CDATA[ guid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ best practices ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Gor Grigoryan ]]>
                </dc:creator>
                <pubDate>Tue, 20 Aug 2024 18:21:25 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724012658962/2e754dc4-248a-4a2b-8819-993514474a22.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-what-are-unique-identifiers">What Are Unique Identifiers? 🪪</h2>
<p>Unique identifiers (UIDs) are crucial components in software engineering and data management. They serve as distinct references for entities within a system and ensure that each item – whether a database record, a user, or a file – can be uniquely identified and accessed.</p>
<p>UIDs are critical for maintaining data, enabling efficient search and retrieval, and supporting large-scale operations in distributed systems. As data volumes and system complexities grow, the need for scalable UID solutions becomes increasingly important.</p>
<p>In this article, you'll learn all about the history of unique identifiers, as well as how some modern solutions work.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><p><a class="post-section-overview" href="#introduction-to-unique-identifiers-">Introduction to Unique Identifiers 🪪</a></p>
<ul>
<li><p><a class="post-section-overview" href="#the-historical-context-of-identifiers">The Historical Context of Identifiers</a></p>
</li>
<li><p><a class="post-section-overview" href="#government-management-of-unique-identifiers">Government Management of Unique Identifiers</a></p>
</li>
<li><p><a class="post-section-overview" href="#structure-of-social-security-numbers">Structure of Social Security Numbers</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#scalability-in-government-systems">Scalability in Government Systems</a></p>
<ul>
<li><p><a class="post-section-overview" href="#tech-companies-and-their-scale">Tech Companies and Their Scale</a></p>
</li>
<li><p><a class="post-section-overview" href="#meta-facebook-">Meta (Facebook)</a></p>
</li>
<li><p><a class="post-section-overview" href="#x-twitter-">X (Twitter)</a></p>
</li>
<li><p><a class="post-section-overview" href="#telegram">Telegram</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#the-role-of-auto-increment-ids-and-their-scalability-issues">The Role of Auto-increment IDs and Their Scalability Issues</a></p>
</li>
<li><p><a class="post-section-overview" href="#sequence-numbers-and-their-advantages-over-auto-increment-ids">Sequence Numbers and Their Advantages Over Auto-increment IDs</a></p>
</li>
<li><p><a class="post-section-overview" href="#uuids-overview-and-usage">UUIDs: Overview and Usage</a></p>
<ul>
<li><p><a class="post-section-overview" href="#what-s-so-great-about-uuids">What's so great about UUIDs?</a></p>
</li>
<li><p><a class="post-section-overview" href="#uuid-version-1">UUID Version 1</a></p>
</li>
<li><p><a class="post-section-overview" href="#uuid-version-4">UUID Version 4</a></p>
</li>
<li><p><a class="post-section-overview" href="#uuid-version-5">UUID Version 5</a></p>
</li>
<li><p><a class="post-section-overview" href="#uuid-version-7">UUID Version 7</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-uuid-version-2-3-and-6">UUID Version 2, 3, and 6</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#snowflake-id">Snowflake ID</a></p>
<ul>
<li><p><a class="post-section-overview" href="#the-problem-stated-by-twitter-">"The Problem" stated by twitter:</a></p>
</li>
<li><p><a class="post-section-overview" href="#finding-tweet-timestamps">Finding Tweet Timestamps</a></p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-the-historical-context-of-identifiers">The Historical Context of Identifiers</h3>
<p>The concept of unique identifiers has enveloped significantly over time, reflecting the growing complexity and scale of human societies and technological systems. To understand why unique identifiers are so important today, let’s look at how we've historically managed identification and how it was developed.</p>
<p>In early human societies, individuals were often identified by a <strong>single name</strong>. This was usually sufficient in small communities where everyone knew each other personally. But as populations grew, it became necessary to distinguish between individuals who shared the same first name. This led to the adoption of <strong>surnames</strong>.</p>
<p>For example, in Armenia 🇦🇲, surnames are used to identify individuals by their family or ancestry. Take the example of a person named Gor. In a small group of up to 50 people, let's say, identifying Gor by his first name alone is easy.</p>
<p>But as the group grows to a larger community of, say, 500 people, additional identifiers become necessary. Gor will be identified as Gor Grigoryan, indicating that he belongs to the Grigoryan family/ancestry. This surname provides a clearer identification and connects Gor to his family's lineage.</p>
<p>As societies continued to expand and bureaucratic systems became more complex, even surnames proved not enough for uniquely identifying individuals. This was especially true in larger cities and for the administration of government services. The need for more robust identification methods became apparent.</p>
<h3 id="heading-government-management-of-unique-identifiers">Government Management of Unique Identifiers</h3>
<p>The introduction of passports in the early 20th century marked a significant step in this direction. Passports included unique personal identifiers, such as passport numbers, to distinguish between individuals clearly. These unique IDs ensured that each person could be accurately identified, regardless of name similarities or other ambiguities.</p>
<p>Several countries pioneered the use of unique personal identification numbers to address this need:</p>
<ul>
<li><p><strong>Germany</strong> 🇩🇪: In the 19th century, Germany implemented a system for tracking individuals for social welfare and military conscription purposes.</p>
</li>
<li><p><strong>Sweden</strong> 🇸🇪: Sweden began issuing personal identification numbers (Personnummer) in the 1940s, providing each citizen with a unique identifier for use in various administrative processes.</p>
</li>
<li><p><strong>France</strong> 🇫🇷: France introduced the National Identification Number (Numéro de Sécurité Sociale) in the mid-20th century to streamline social security administration and other government services.</p>
</li>
<li><p><strong>United States</strong> 🇺🇸: The USA followed with the introduction of Social Security Numbers (SSNs) in 1936 as part of the Social Security Act. This approach to unique identification has since been adopted worldwide, with countries issuing national identification numbers to their citizens.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-49.png" alt="image-49" width="600" height="400" loading="lazy"></p>
<p>Information page, Edwin James Tharp’s passport, March 27, 1936, <a target="_blank" href="https://library.csun.edu/SCA/Peek-in-the-Stacks/identities">Robert and Eva Tharp Collection</a>.</p>
<p>As illustrated in the example image, the 1936 UK 🇬🇧 passport included detailed personal information such as eye color, hair color, profession, height, and information about the holder’s spouse and children.</p>
<h3 id="heading-structure-of-social-security-numbers">Structure of Social Security Numbers</h3>
<p>A Social Security Number (SSN) in the United States is a nine-digit number formatted as "AAA-GG-SSSS". Each part of the SSN has historically carried specific information:</p>
<ol>
<li><p><strong>Area Number (AAA)</strong>: Originally, the first three digits, known as the area number, represented the geographical region where the SSN was issued. This regional assignment helped to ensure a systematic distribution of numbers across the country.</p>
</li>
<li><p><strong>Group Number (GG)</strong>: The middle two digits, called the group number, were used to organize the numbers within a given area. The group numbers ranged from 01 to 99 and were issued in a specific order to prevent duplicate numbers within the same area.</p>
</li>
<li><p><strong>Serial Number (SSSS)</strong>: The last four digits are the serial number, which sequentially identifies each individual within a group. This part of the SSN ensures that even if the area and group numbers are the same, the overall SSN remains unique.</p>
</li>
</ol>
<p>The Social Security Administration (SSA) has implemented several measures to ensure that each SSN is unique for the entire USA population (<strong>341.9 million people).</strong></p>
<p>Governments around the world manage unique identifiers primarily for administrative purposes, such as social security, taxation, and national identification. These systems are designed to handle large populations and ensure that every citizen has a unique identifier for official records.</p>
<p>For example, the United States 🇺🇸 Social Security Administration (SSA) manages Social Security Numbers (SSNs) for over 330 million people. Similarly, the Indian 🇮🇳 government has issued Aadhaar numbers, a 12-digit unique identifier, to over <strong>1.3 billion citizens</strong>. These identifiers are crucial for accessing government services, benefits, and other official processes.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-52.png" alt="image-52" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Aadhaar">Aadhaar is the world's largest biometric ID system</a> described as "the most sophisticated ID program in the world".</p>
<h2 id="heading-scalability-in-government-systems">Scalability in Government Systems</h2>
<p>While government systems are large, they generally do not face the same scalability challenges as tech companies. Government databases are often centralized, and the rate at which new identifiers are issued is relatively steady and predictable. Also, the frequency of updates and interactions with these identifiers is lower compared to the dynamic environment of tech companies.</p>
<p>Tech companies, especially social media giants, operate on an entirely different scale. These companies manage billions of users and generate vast amounts of data daily. For instance, Meta (formerly Facebook) has over 3 billion monthly active users across its platforms, including Facebook, Instagram, and WhatsApp.</p>
<h3 id="heading-tech-companies-and-their-scale">Tech Companies and Their Scale</h3>
<p>Let's take a few examples:</p>
<h4 id="heading-meta-facebook">Meta (Facebook)</h4>
<ol>
<li><p><strong>User Base</strong>: With over <strong>3 billion monthly active users</strong>, Meta needs a robust system to ensure that each user is uniquely identified.</p>
</li>
<li><p><strong>Posts and Interactions</strong>: Facebook alone sees approximately <strong>350 million new posts daily</strong>. Each of these posts, along with comments, likes, and shares require a unique identifier to manage interactions efficiently.</p>
</li>
<li><p><strong>Messages</strong>: WhatsApp users send around <strong>100 billion messages every day</strong>, each needing a unique identifier to ensure messages are correctly routed and stored.</p>
</li>
<li><p><strong>Unique Data Rows</strong>: With the combination of user profiles, posts, comments, likes, and messages, Meta likely manages over <strong>10+ trillion unique data rows</strong>. (If the global population is approximately 8 billion people, then 10 trillion people would be about <strong>1,250</strong> times the current global population).</p>
</li>
</ol>
<h4 id="heading-x-twitter">X (Twitter)</h4>
<p>Twitter, another social media giant, has about <strong>450 million monthly active users</strong>. On average, users send around <strong>500 million tweets per day</strong>. Each tweet, reply, and retweet needs a unique identifier to maintain the platform's integrity and usability.</p>
<h4 id="heading-telegram">Telegram</h4>
<p>Telegram is known for its high-traffic and robust messaging platform. With over <strong>700 million monthly active users</strong>, Telegram experiences particularly high traffic spikes during events like New Year's Eve, where users send billions of messages within a short timeframe.</p>
<p>On a typical day, Telegram handles over <strong>70 billion messages</strong>. Each message, channel post, and group interaction requires a unique identifier to ensure proper delivery and organization.</p>
<p>The scale at which tech companies operate requires sophisticated and highly scalable unique identifier systems. These systems must handle high concurrency, support distributed architectures, and ensure low latency.</p>
<h2 id="heading-the-role-of-auto-increment-ids-and-their-scalability-issues">The Role of Auto-increment IDs and Their Scalability Issues</h2>
<p>Auto-increment IDs are a common method for generating unique identifiers in relational databases. When a new record is added to a table, the database automatically assigns the next available integer value to the ID field. This method is straightforward and ensures that each record within a table has a unique identifier without requiring any manual intervention.</p>
<p>Consider a table for storing user information in a relational database. When the first user is added, they might be assigned an ID of 1. The second user would receive an ID of 2, and so on.</p>
<p>While auto-increment IDs are simple and effective for small-scale applications, they face significant challenges in larger, distributed systems.</p>
<ol>
<li><p><strong>Concurrency Issues</strong>: In high-traffic applications, multiple transactions might attempt to insert records simultaneously. Ensuring that each transaction receives a unique auto-increment ID can lead to performance bottlenecks and require complex locking mechanisms.</p>
</li>
<li><p><strong>Distributed Systems</strong>: In distributed databases, where data is spread across multiple servers, maintaining a global sequence for auto-increment IDs becomes problematic. Each server would need to coordinate with others to avoid generating duplicate IDs, which can significantly impact performance and reliability.</p>
</li>
<li><p><strong>Single Point of Failure</strong>: Relying on a central authority to generate auto-increment IDs introduces a single point of failure. If the server responsible for assigning IDs goes down, the entire system might be unable to add new records.</p>
</li>
<li><p><strong>Predictability</strong>: Auto-increment IDs are predictable. If someone knows the ID of one record, they can infer the IDs of subsequent records. This predictability can be a security concern in certain applications, such as those involving financial transactions or sensitive user data.</p>
</li>
</ol>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> Admins (
    <span class="hljs-keyword">Id</span> <span class="hljs-built_in">SERIAL</span> PRIMARY <span class="hljs-keyword">KEY</span>,
    <span class="hljs-keyword">Name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>
);

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">Users</span> (
    <span class="hljs-keyword">Id</span> <span class="hljs-built_in">SERIAL</span> PRIMARY <span class="hljs-keyword">KEY</span>,
    <span class="hljs-keyword">Name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>
);

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> Admins (<span class="hljs-keyword">Name</span>)
<span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'GorGrigoryan'</span>),
       (<span class="hljs-string">'GorGrigoryan2'</span>);

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> Admins;


<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | Id | Name          |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 1  | GorGrigoryan  |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 2  | GorGrigoryan2 |</span>
<span class="hljs-comment">-- +----+---------------+</span>
</code></pre>
<h2 id="heading-sequence-numbers-and-their-advantages-over-auto-increment-ids">Sequence Numbers and Their Advantages Over Auto-increment IDs</h2>
<p>Sequence numbers are a method of generating unique identifiers by maintaining a counter that is incremented with each new record. Unlike auto-increment IDs, which are typically limited to a single database instance, sequence numbers can be designed to work across distributed systems, addressing some of the scalability and concurrency issues associated with auto-increment IDs.</p>
<p>How sequence numbers work:</p>
<ol>
<li><p><strong>Centralized Sequence Generators</strong>: A central service or database table generates and manages the sequence numbers. Each request for a new identifier increments the counter and returns the next value.</p>
</li>
<li><p><strong>Distributed Sequence Generators</strong>: In a distributed environment, sequence numbers can be generated by dividing the range of possible values among different nodes or using more complex algorithms to ensure uniqueness without central coordination.</p>
</li>
</ol>
<p>Consider a distributed database system with multiple nodes, each responsible for generating unique sequence numbers. The system might allocate ranges of sequence numbers to each node, ensuring that they can generate identifiers independently:</p>
<ul>
<li><p><strong>Node 1</strong>: Allocated sequence numbers 1,000,000 to 1,999,999</p>
</li>
<li><p><strong>Node 2</strong>: Allocated sequence numbers 2,000,000 to 2,999,999</p>
</li>
<li><p><strong>Node 3</strong>: Allocated sequence numbers 3,000,000 to 3,999,999</p>
</li>
</ul>
<p>Each node can now generate up to one million unique identifiers without needing to communicate with a central server. This approach improves scalability and performance, particularly in environments with high write loads.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">SEQUENCE</span> UserIdentifier
<span class="hljs-keyword">INCREMENT</span> <span class="hljs-number">1</span>
<span class="hljs-keyword">START</span> <span class="hljs-number">1</span>;

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> Admins (
    <span class="hljs-keyword">Id</span> <span class="hljs-built_in">INT</span> PRIMARY <span class="hljs-keyword">KEY</span>,
    <span class="hljs-keyword">Name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>
);

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">Users</span> (
    <span class="hljs-keyword">Id</span> <span class="hljs-built_in">INT</span> PRIMARY <span class="hljs-keyword">KEY</span>,
    <span class="hljs-keyword">Name</span> <span class="hljs-built_in">VARCHAR</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>
);


<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> Admins (<span class="hljs-keyword">Id</span>, <span class="hljs-keyword">Name</span>)
<span class="hljs-keyword">VALUES</span>(<span class="hljs-keyword">nextval</span>(<span class="hljs-string">'UserIdentifier'</span>), <span class="hljs-string">'GorGrigoryan'</span>),
(<span class="hljs-keyword">nextval</span>(<span class="hljs-string">'UserIdentifier'</span>), <span class="hljs-string">'GorGrigoryan2'</span>);

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-keyword">Users</span> (<span class="hljs-keyword">Id</span>, <span class="hljs-keyword">Name</span>)
<span class="hljs-keyword">VALUES</span>(<span class="hljs-keyword">nextval</span>(<span class="hljs-string">'UserIdentifier'</span>), <span class="hljs-string">'UserGorGrigoryan'</span>),
(<span class="hljs-keyword">nextval</span>(<span class="hljs-string">'UserIdentifier'</span>), <span class="hljs-string">'UserGorGrigoryan2'</span>);


<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> Admins;

<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | Id | Name          |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 1  | GorGrigoryan  |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 2  | GorGrigoryan2 |</span>
<span class="hljs-comment">-- +----+---------------+</span>

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">Users</span>;

<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | Id | Name          |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 3  | GorGrigoryan  |</span>
<span class="hljs-comment">-- +----+---------------+</span>
<span class="hljs-comment">-- | 4  | GorGrigoryan2 |</span>
<span class="hljs-comment">-- +----+---------------+</span>
</code></pre>
<p>Another advantage of using sequence numbers is that you can obtain the ID of the entity before it is inserted into the database.</p>
<p>In the case of auto-increment IDs, this assignment is typically handled by the database upon insertion, which can limit flexibility. With sequence numbers, you can easily generate the ID on the application side, which can be an easy task when using some ORMs e.g the EF Core ORM in C#</p>
<p>Check out sequence numbers on the SQL server <a target="_blank" href="https://learn.microsoft.com/en-us/sql/relational-databases/sequence-numbers/sequence-numbers?view=sql-server-ver16">here</a>.</p>
<h2 id="heading-uuids-overview-and-usage">UUIDs: Overview and Usage</h2>
<p>GUIDs (Globally Unique Identifiers), also known as UUIDs (Universally Unique Identifiers), are 128-bit identifiers designed to be globally unique. A typical UUID is displayed in a 32-character hexadecimal string, divided into five groups separated by hyphens. For example: <code>126e3456-e89b-12d3-a456-426614174000</code>.</p>
<h3 id="heading-whats-so-great-about-uuids">What's so great about UUIDs?</h3>
<p>One of the standout features of GUIDs is their huge capacity for uniqueness. With a 128-bit structure, the total number of possible GUIDs is very large: Specifically, there are <code>340,282,366,920,938,463,463,374,607,431,770,000,000</code> GUIDs available. To put that into perspective, let's compare it with something tangible.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-94.png" alt="image-94" width="600" height="400" loading="lazy"></p>
<p>Did you know that scientists have attempted to calculate the number of grains of sand on Earth? Science writer David Blatner, in his book <a target="_blank" href="https://www.amazon.com/Spectrums-Mind-boggling-Universe-Infinitesimal-Infinity/dp/1620405202">Spectrums</a>, mentions that a group of researchers at the University of Hawaii tried to estimate this number. They determined that Earth has roughly (and we are speaking very roughly) 7.5 x 10<sup>18</sup> grains of sand, or seven quintillion, five hundred quadrillion grains. For more, consider reading the article titled: "<a target="_blank" href="https://www.npr.org/sections/krulwich/2012/09/17/161096233/which-is-greater-the-number-of-sand-grains-on-earth-or-stars-in-the-sky"><strong>Which Is Greater, The Number Of Sand Grains On Earth Or Stars In The Sky?</strong></a><strong>"</strong></p>
<p>Now, to compare those numbers:</p>
<pre><code class="lang-sql">| GUIDs available | 340,282,366,920,938,463,463,374,607,431,770,000,000
| Sand grains     | 75,000,000,000,000,000,000
</code></pre>
<p>If you decided to create an application to track every grain of sand on Earth and assign each a unique identifier, you could easily do that using GUIDs. The fun part is that you could actually repeat this process <code>4,537,098,225,612,512,846</code> times over without running out of unique GUIDs! 🤯</p>
<h3 id="heading-uuid-version-1">UUID Version 1</h3>
<p>UUID Version 1 generates unique identifiers based on the current timestamp, clock sequence, and node identifier (typically the MAC address of the machine generating the UUID).</p>
<p>According to <a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc4122">RFC 4122</a>, the timestamp is the number of nanoseconds since October 15, 1582, at midnight UTC. Most computers do not have a clock that ticks fast enough to measure time in nanoseconds. Instead, a random number is often used to fill in timestamp digits beyond the computer's measurement accuracy.</p>
<p>When multiple version-1 UUIDs are generated in a single API call, the random portion may be incremented rather than regenerated for each UUID. This ensures uniqueness and is faster to generate.</p>
<p>UUID v1 also has the mac address attached to it. By including a MAC address in the UUID, you can be sure that two different computers will never generate the same UUID. Because MAC addresses are globally unique, but also note that version-1 UUIDs can be traced back to the computer that generated them.</p>
<p>This ensures that the UUID is unique across both time and space. It is suitable when the <strong>generation time and machine uniqueness</strong> are important. It is often used in systems where the timestamp of creation is relevant or needed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-95.png" alt="image-95" width="600" height="400" loading="lazy"></p>
<p>(Image from <a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc4122">here</a>)</p>
<h3 id="heading-uuid-version-4">UUID Version 4</h3>
<p>UUID Version 4 generates identifiers using random or pseudo-random numbers. This method ensures a high probability of uniqueness due to the vast number of possible GUIDs. This is the most common UUID version.</p>
<p>There are 2 main variants of UUID:</p>
<ul>
<li><p>Variant 1: <a target="_blank" href="https://minecraft.fandom.com/wiki/Universally_unique_identifier">Minecraft UUID</a>, also called Timestamp-first UUIDs</p>
</li>
<li><p>Variant 2:  "GUID"</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-96.png" alt="image-96" width="600" height="400" loading="lazy"></p>
<p>(<a target="_blank" href="https://www.uuidtools.com/minecraft">Image from here</a>)</p>
<p>GUID is entirely random, making it simple to generate and ensuring that each identifier is unique with a very high probability. The unique identifiers are made up of 128 bits. They are written as 32 characters using numbers (0-9) and letters (A-F). The characters are grouped in a specific format: 8-4-4-4-12, separated by hyphens, like this: <code>{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}</code>.</p>
<p>The great thing about GUIDs is that you don’t need a central system to create them. Anyone can generate a GUID using an algorithm, and it will still be unique across different systems and applications. They are designed to be used nearly everywhere a unique identifier is needed. Here are some usage examples:</p>
<ul>
<li><p>Windows: Uses GUIDs to generate unique product keys</p>
</li>
<li><p>Microsoft SQL Server: Uses GUIDs as primary keys to ensure global uniqueness across distributed databases</p>
</li>
<li><p>AWS: Uses GUIDs for uniquely identifying resources in their cloud infrastructure, such as EC2 instances and S3 objects</p>
</li>
<li><p>eBay: Uses GUIDs to identify listings, transactions, and users</p>
</li>
</ul>
<h3 id="heading-uuid-version-5">UUID Version 5</h3>
<p>UUID Version 5 generates unique identifiers based on a <strong>namespace</strong> identifier and a <strong>name</strong>. The namespace and name are combined and hashed using SHA-1 to produce the UUID. This ensures that the same namespace and name combination will always produce the same UUID. In UUID, the namespace must be a UUID, and the name can be anything.</p>
<p>UUID V5 is useful for generating consistent unique identifiers for the same input data across different systems and contexts. Let's say we want to generate a user id based on their username. Here’s how you can achieve this in C#:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-97.png" alt="image-97" width="600" height="400" loading="lazy"></p>
<p>Here the UUID Version 5 solves several important problems, particularly when you need a consistent and unique identifier based on a given input.</p>
<p>For instance, consider a scenario where you need a user ID to make an API call (or anything else), but in your code, you only have the username accessible. How would the problem be solved if we were using UUID Version 4 (GUIDs)? Most likely, it would work something like this:</p>
<pre><code class="lang-csharp"><span class="hljs-comment">/* When using GUID (UUID v4) */</span>

<span class="hljs-keyword">var</span> userName = <span class="hljs-string">"bob"</span>; <span class="hljs-comment">// Lets assume we only have username</span>
<span class="hljs-comment">// API call or DB call to get the user id using name</span>
<span class="hljs-keyword">var</span> userId = <span class="hljs-keyword">await</span> userService.GetUserIdAsync(userName);

<span class="hljs-keyword">await</span> userService.ChangeUserNameAsync(userId, <span class="hljs-string">"bob-2"</span>);
</code></pre>
<p>By using UUID Version 5 with a shared namespace across all your projects, you can easily generate the user ID from the username without making any additional API calls. So the same code would look like this:</p>
<pre><code class="lang-csharp"><span class="hljs-comment">/* When using UUID v5 */</span>

<span class="hljs-comment">// From some shared code</span>
<span class="hljs-keyword">var</span> userNamespace = SharedConstants.UserNamespace;

<span class="hljs-keyword">var</span> userName = <span class="hljs-string">"bob"</span>; <span class="hljs-comment">// Lets assume we only have username</span>

<span class="hljs-comment">//Generate the user id in place, without additional call</span>
<span class="hljs-keyword">var</span> userId = Uuid.NewNameBased(userNamespace, userName);

<span class="hljs-keyword">await</span> userService.ChangeUserNameAsync(userId, <span class="hljs-string">"bob-2"</span>);
</code></pre>
<p>This approach eliminates the need for redundant API calls. In a distributed system, making an API call to fetch a user ID every time you need it can be inefficient and slow. With UUID Version 5, you can locally generate the user ID from the username (or any other input), reducing the need for network requests and significantly improving the efficiency of your application.</p>
<p>What kind of problem have we solved with UUID v5? Let's say you need a user ID to make an API call but in your code, you have only a username, if you have the namespace shared across all your projects. Then you can easily get the user id using a username, without making any API call. That's because UUID v5 always reproduces the same UUID for the same input.</p>
<p>Also, UUID Version 5 ensures uniqueness and consistency across different systems. When integrating multiple systems or microservices, it can be challenging to keep user IDs consistent across various services. By using the same namespace and the same input (such as a username), UUID Version 5 guarantees that the generated IDs are unique and consistent across all systems, facilitating smoother integration and data consistency.</p>
<h3 id="heading-uuid-version-7">UUID Version 7</h3>
<p>GUID Version 7 is a proposed new version that aims to combine the strengths of both timestamp-based and random-based GUIDs.</p>
<h4 id="heading-problems-with-uuid-v4-guid"><strong>Problems with UUID v4 (GUID)</strong></h4>
<p>UUID Version 4 generates non-time-ordered values, meaning the identifiers created are not sequential. Since these values are randomly generated, they won't be clustered together in a database index. Instead, inserts will occur at random locations, which can negatively impact the performance of common index data structures, such as B-trees and their variants.</p>
<p>In a scenario where your product requires <em>frequent access to recent data</em>, non-sequential identifiers create a significant challenge.</p>
<p>With UUID Version 4, the most recent data will be inserted randomly throughout the index, <em>lacking clustering</em>. As a result, retrieving the most recent data from a large dataset requires traversing numerous database index pages.</p>
<p>In contrast, using sequential identifiers ensures that the latest data is logically arranged at the right-most part of the index, making it much more cache-friendly. This organization allows for faster and more efficient retrieval of recent data, as it minimizes the number of index pages that need to be accessed which is a lack in UUID v4.</p>
<h4 id="heading-the-solution-with-uuid-v7"><strong>The solution with UUID v7</strong></h4>
<p>UUID v7 is designed to provide unique and sortable identifiers that are both easy to generate and useful for distributed systems. It uses a combination of timestamps and random data to ensure both uniqueness and temporal order.</p>
<p>The first part of the UUID is a timestamp that provides a chronological component, ensuring that UUIDs generated close together in time are also close together in value. The remaining part is filled with random data, ensuring the uniqueness of each identifier.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/image-98.png" alt="image-98" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://buildkite.com/blog/goodbye-integers-hello-uuids">Buildkite post about migrating to UUID v7</a></p>
<h3 id="heading-uuid-versions-2-3-and-6">UUID Versions 2, 3, and 6</h3>
<p>You may have noticed that our discussion focuses on UUID Versions 1, 4, 5, and 7, and skips over Versions 2, 3, and 6. Here's why:</p>
<ul>
<li><p><strong>UUID Version 2</strong>: This version is rarely used in modern applications. It’s similar to Version 1 but includes additional fields for things like domain information (such as POSIX UID or GID). It was mainly used in legacy systems and is now considered largely obsolete.</p>
</li>
<li><p><strong>UUID Version 3</strong>: This version is based on a name and a namespace, similar to Version 5. The main difference is that Version 3 uses the MD5 hashing algorithm, which is less secure and less efficient than the SHA-1 algorithm used in Version 5. Version 5 is generally preferred because SHA-1 is more robust.</p>
</li>
<li><p><strong>UUID Version 6</strong>: Version 6 is still under draft as a proposed standard. It is meant to provide a time-ordered UUID with better performance for distributed systems, but since it hasn't been fully adopted yet, we focus on Version 7, which offers similar features and has more momentum.</p>
</li>
</ul>
<h2 id="heading-snowflake-id">Snowflake ID</h2>
<p>Snowflake ID is a unique identifier generation system developed by Twitter to address the challenges of generating unique, sequential, and distributed identifiers in a highly scalable and efficient manner.</p>
<p>Unlike GUIDs, which are often non-sequential and can cause performance issues in database indexing, Snowflake IDs are designed to be both time-ordered and globally unique, making them ideal for distributed systems and databases where sequential order is important.</p>
<p>A Snowflake ID is a 64-bit integer composed of several distinct parts:</p>
<ol>
<li><p><strong>Timestamp (41 bits):</strong> The largest portion of the Snowflake ID is the timestamp, which records the number of milliseconds since a custom epoch (often set to the date when the system was first deployed). This ensures that IDs are time-ordered and can be easily sorted based on their creation time.</p>
</li>
<li><p><strong>Datacenter ID (5 bits):</strong> This part of the ID identifies the datacenter where the ID was generated, allowing the system to generate unique IDs across multiple data centers without conflicts.</p>
</li>
<li><p><strong>Machine ID (5 bits):</strong> Similar to the datacenter ID, the machine ID identifies the specific server or machine within the datacenter that generated the ID. This ensures that even within the same data center, IDs remain unique.</p>
</li>
<li><p><strong>Sequence Number (12 bits):</strong> The sequence number is used to differentiate between multiple IDs generated within the same millisecond by the same machine. <em>With 12 bits, up to 4,096 unique IDs can be generated per machine per millisecond.</em></p>
</li>
</ol>
<p>The format was created by Twitter (now X) and is used for the IDs of tweets. It is popularly believed that every snowflake has a unique structure, so they took the name "snowflake ID". The format has been adopted by other companies, including Discord and Instagram. The Mastodon social network uses a modified version.</p>
<p>The format was first announced by X/Twitter in June 2010. Due to implementation challenges, <a target="_blank" href="https://techcrunch.com/2010/10/12/twitter-snowflake/">they waited until later in the year to roll out the update</a>.</p>
<ul>
<li><p>X uses snowflake IDs for posts, direct messages, users, lists, and all other objects available over the API.</p>
</li>
<li><p>Discord also uses snowflakes, with their epoch set to the first second of the year 2015.</p>
</li>
<li><p>Instagram uses a modified version of the format, with 41 bits for a timestamp, and 10 bits for a sequence number.</p>
</li>
<li><p>Mastodon's modified format has 48 bits for a millisecond-level timestamp, as it uses the UNIX epoch. The remaining 16 bits are for sequence data.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/image-3.png" alt="image-3" width="600" height="400" loading="lazy"></p>
<h3 id="heading-the-problem-stated-by-twitter">"The Problem" stated by Twitter:</h3>
<blockquote>
<p>We currently use MySQL to store most of our online data. In the beginning, the data was in one small database instance which in turn became one large database instance and eventually many large database clusters. For various reasons, the details of which merit a whole blog post, we’re working to replace many of these systems with <a target="_blank" href="http://cassandra.apache.org/">the Cassandra distributed database</a> or horizontally sharded MySQL (using <a target="_blank" href="http://github.com/twitter/gizzard">gizzard</a>).</p>
<p>Unlike MySQL, Cassandra has no built-in way of generating unique ids – nor should it, since at the scale where Cassandra becomes interesting, it would be difficult to provide a one-size-fits-all solution for ids. Same goes for sharded MySQL. We needed something that could generate tens of thousands of ids per second in a highly available manner.</p>
<p>This naturally led us to choose an uncoordinated approach. These ids need to be <em>roughly sortable</em>, meaning that if tweets A and B are posted around the same time, they should have ids in close proximity to one another since this is how we and most Twitter clients sort tweets.</p>
<p>Additionally, these numbers have to fit into 64 bits. We’ve been through the painful process of growing the number of bits used to store tweet ids <a target="_blank" href="http://www.twitpocalypse.com/">before</a>. It’s unsurprisingly hard to do when you have over <a target="_blank" href="http://social.venturebeat.com/2010/04/14/twitter-applications/">100,000 different codebases involved</a>.</p>
</blockquote>
<p>Check out <a target="_blank" href="https://blog.x.com/engineering/en_us/a/2010/announcing-snowflake">here</a> for more information</p>
<h3 id="heading-finding-tweet-timestamps">Finding Tweet Timestamps</h3>
<p>We all know that deleting a tweet isn't truly possible—once it's out there, it's how Twitter is designed. However, Twitter's use of Snowflake IDs adds an interesting twist to this narrative. Snowflake IDs are designed to be unique and time-ordered, which makes them not just identifiers but also a trail that can be tracked.</p>
<p>On May 11, 2019, Derek Willis from Politwoops uncovered a <a target="_blank" href="https://gist.github.com/naumansiddiqui4/ba3398ea85ed0ef1f3af23d47b4dcd42">list of deleted tweet IDs</a>. By using the Snowflake structure, he was able to extract the timestamps from these IDs, and discovered the 107 missing tweets. This finding inspired the creation of TweetedAt, a tool designed to accurately retrieve timestamps from Snowflake IDs and estimate the timing of tweets generated before Snowflake was in use.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/image-2.png" alt="image-2" width="600" height="400" loading="lazy"></p>
<p>Check out <a target="_blank" href="https://ws-dl.blogspot.com/2019/08/2019-08-03-tweetedat-finding-tweet.html">here.</a></p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>Unique identifiers play a critical role in software engineering, ensuring data integrity and enabling efficient data management across distributed systems.</p>
<p>From traditional GUIDs to modern solutions like Snowflake IDs, each identifier system offers distinct advantages tailored to specific use cases.</p>
<p>As technology evolves, understanding these systems and their implementations becomes increasingly important for scaling applications effectively. By exploring the various versions and alternatives, we can make informed decisions that best suit our needs in managing data at scale.</p>
<h4 id="heading-cover-image-a-2017-post-celebrating-facebook-reaching-2-billion-usershttpswwwfacebookcomphotofbid10103832396388711ampseta941146602501">Cover image: <a target="_blank" href="https://www.facebook.com/photo/?fbid=10103832396388711&amp;set=a.941146602501">A 2017 post celebrating Facebook reaching 2 billion users</a>.</h4>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Decoding Chaos: How True Randomness Works in Software Engineering ]]>
                </title>
                <description>
                    <![CDATA[ Understanding Randomness When you hear the word "randomness," what usually comes to mind? You may think of  something intangible, an abstract concept without a specific shape or form  – it's random.  But randomness is much more than an abstract idea ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/true-randomness-in-software-engineering/</link>
                <guid isPermaLink="false">66c3770d86ad38fd983838a6</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ randomness ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Software Engineering ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Gor Grigoryan ]]>
                </dc:creator>
                <pubDate>Mon, 06 May 2024 16:27:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/0_VRBzKmnCSxIHtVVQ.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-understanding-randomness">Understanding Randomness</h2>
<p>When you hear the word "randomness," what usually comes to mind? You may think of  something intangible, an abstract concept without a specific shape or form  – it's random. </p>
<p>But randomness is much more than an abstract idea – it's a fundamental aspect of our daily decisions and choices. Whether it's deciding what to eat for breakfast or picking a number from 1 to 10 in a game, randomness plays a crucial role. </p>
<p>Randomness isn't just about unpredictability. It's also about the lack of pattern or predictability in events. For instance, when you toss a coin, the outcome of heads or tails is random because it's equally likely and unpredictable. </p>
<h3 id="heading-why-is-randomness-important-in-software-engineering">Why is Randomness Important in Software Engineering?</h3>
<p>This concept is incredibly important in the field of software engineering, where generating true randomness can enhance security, simulations, and algorithms. In software development, this unpredictability is not just a feature—it's a fundamental requirement for various critical functions.</p>
<h4 id="heading-security">Security</h4>
<p>The most crucial role of randomness in software is in the realm of security. Random numbers are used to generate secure keys for encryption, ensuring that sensitive data—be it personal information, financial details, or confidential communications—is protected from unauthorized access. </p>
<p>The randomness ensures that these keys cannot be easily predicted or replicated, fortifying the security barriers (see more in the <a class="post-section-overview" href="#heading-randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</a> section)</p>
<h4 id="heading-testing-and-quality-assurance">Testing and Quality Assurance</h4>
<p>Developers use random inputs to simulate how software might perform under different conditions. This approach helps uncover unexpected bugs and ensures that the software can handle a variety of scenarios, improving its reliability and stability. </p>
<p>Companies like Netflix, Facebook, Google use Chaos Engineering to make their systems more reliable (learn more in the <a class="post-section-overview" href="#heading-chaos-monkey-developed-my-netflix">Chaos Engineering section</a>).</p>
<h4 id="heading-simulation-and-modeling">Simulation and Modeling</h4>
<p>Randomness is a key component in simulations that mimic real-world phenomena, which can be inherently unpredictable. Whether it's modeling climate patterns, economic markets, or traffic flows, randomness helps create more accurate models that better reflect the complexity of these systems.</p>
<h4 id="heading-additional-applications">Additional Applications</h4>
<p>Randomness is used in many areas and it helps distribute tasks across servers in load balancing, improves efficiency in traffic routing, and adds realism in image generation. Also, its crucial for creating unique identifiers like GUIDs (Globally Unique Identifiers) and shuffling playlists to enhance user experience. As you can see, the use cases for randomness are numerous.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>This article is designed to be accessible, with explanations straightforward enough for readers with various backgrounds. However, a few basic prerequisites can enhance your understanding:</p>
<ol>
<li><strong>Basic Programming Knowledge</strong>: While not essential, some familiarity with programming concepts in languages like C#, Java, or Python could help you grasp examples of how randomness is implemented in code more quickly.</li>
<li><strong>Elementary Math Skills</strong>: A basic understanding of probability and statistics is beneficial but not necessary, as the article aims to explain these concepts in simple terms.</li>
<li><strong>Introductory Cryptography</strong>: If you're curious about the security aspects of randomness, some background in cryptography concepts like encryption and key generation could be helpful.</li>
</ol>
<p>Overall, the article is structured to be easy to follow, with no advanced knowledge required. It's meant to introduce the concept of randomness in software engineering broadly, making it suitable for readers from diverse fields.</p>
<h3 id="heading-heres-what-well-cover-in-this-article">Here's what we'll cover in this article:</h3>
<ul>
    <li><a href="#understanding-randomness">Understanding Randomness</a></li>
    <li><a href="#coin-toss-paradigm">Coin Toss Paradigm</a></li>
    <li><a href="#the-illusion-of-human-randomness">The Illusion of Human Randomness</a></li>
    <li><a href="#how-random-number-generators-work">How Random Number Generators Work</a>
        <ul>
            <li><a href="#simple-random-number-generator">Simple random number generator</a></li>
        </ul>
    </li>
    <li><a href="#true-random-number-generation-trng-and-entropy-sources">True Random Number Generation (TRNG) and Entropy Sources</a>
        <ul>
            <li><a href="#earthquakes-in-trng">Earthquakes in TRNG</a></li>
            <li><a href="#hardware-events-in-trng">Hardware Events in TRNG</a></li>
            <li><a href="#human-factors-in-trng">Human Factors in TRNG</a></li>

        </ul>
    </li>
    <li>
        <a href="#randomness-in-software-testing">Randomness in software testing</a>
        <ul>
            <li><a href="#chaos-monkey-developed-my-netflix">Chaos Monkey developed my Netflix
</a></li>
        </ul>
    </li>
    <li><a href="#randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</a>
        <ul>
            <li><a href="#could-you-hack-the-encryption">Could you hack the encryption?</a></li>
        </ul>
    </li>
    <li><a href="#randomness-in-simulation-and-modeling">Randomness in Simulation and Modeling</a>
        <ul>
            <li><a href="#monte-carlo-simulation">Monte Carlo Simulation</a></li>
        </ul>
    </li>
    <li><a href="#future-of-randomness-in-software-engineering">Future of Randomness in Software Engineering</a>
        <ul>
            <li><a href="#quantum-computing-and-quantum-randomness">Quantum Computing and Quantum Randomness</a></li>
        </ul>
    </li>
    <li><a href="#wrapping-up">Wrapping Up</a></li>
</ul>


<h2 id="heading-coin-toss-paradigm">Coin Toss Paradigm</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Phantom_Slowmo_Coin_Flip--1-.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Is tossing a coin truly a random event?</strong> At first glance, a coin toss represents the paradigm of randomness : two outcomes, each with an equal chance of occurring. </p>
<p>But if we dive deeper into the physics behind a coin toss, the story starts to unfold differently. Hypothetically, if we could control and replicate every variable involved in the toss  – the force applied, the angle of the toss, the air resistance, and even the surface it lands on –  would the outcome still be unpredictable?</p>
<p>The answer leans towards a surprising declaration: in a perfectly controlled environment, the result of a coin toss could be predicted with near certainty. This challenges our understanding of randomness, suggesting that what we often perceive as random is influenced by numerous factors, many of which are beyond our control or too complex to replicate in practice.</p>
<p>Thus, we arrive at an insightful conclusion that randomness ≈ the result of variables that are exceedingly difficult to replicate.</p>
<p>Big research from the University of California at Berkeley, titled “<a target="_blank" href="https://www.stat.berkeley.edu/~aldous/157/Papers/diaconis_coinbias.pdf"><strong>Dynamical Bias in the Coin Toss</strong></a>”, delves into this phenomenon:</p>
<blockquote>
<p>Abstract: We analyze the natural process of flipping a coin which is caught in the hand. We show that vigorously flipped coins tend to come up the same way they started. The limiting chance of coming up this way depends on a single parameter, the angle between the normal to the coin and the angular momentum vector. Measurements of this parameter based on high-speed photography are reported. For natural flips, the chance of coming up as started is about .51</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-36.png" alt="Image" width="600" height="400" loading="lazy">
_[<strong>Dynamical Bias in the Coin Toss</strong>](https://www.stat.berkeley.edu/~aldous/157/Papers/diaconis<em>coinbias.pdf" rel="noopener)</em></p>
<h2 id="heading-the-illusion-of-human-randomness">The Illusion of Human Randomness</h2>
<p>For humans, it's an easy task to generate a random number, say a random word, or make a random decision. But again, is it really a random thing and can it be somehow predicted like we have stated for a coin toss? </p>
<p>If you have seen the 2015 movie Focus, you may remember the "priming" scene where they spend the day "priming" their victim to subconsciously recognize and choose the number 55 by having it represented all around him.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/otWiLwwxo5o" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>Priming is one of the most important psychological principles to understand because it influences behavior through implicit memory. In other words, exposure to a cue in one setting can form an association that carries into another.</p>
<p>One of the examples of priming comes to us from a supermarket bottle shop. Imagine one week you go into the bottle shop and there’s some French music playing in the background. You buy your wine and leave. </p>
<p>Now imagine you return a week later, but this time German music is piping through the speakers. Again, you buy your wine and leave. Chances are that when French music was playing, you purchased French wine, and when German music was playing, German wine – just like 77% and 73% of research participants did. </p>
<p>Were these consumers aware of the music and its impact on their decision? 86% of people said no, the music had no effect.</p>
<p>This phenomenon underscores a profound truth: <a target="_blank" href="https://www.quora.com/What-is-the-psychological-theory-behind-the-priming-scene-in-Will-Smiths-movie-Focus">whether knowingly or not, we are both the primers and the primed</a>. Our perceived randomness in decision-making is continuously shaped by the stimuli around us. This reveals that the essence of human randomness is far more complex and influenced than we might initially believe.</p>
<h2 id="heading-how-random-number-generators-work">How Random Number Generators Work</h2>
<p>Let’s take a journey back to the early days of computing to understand the evolution of random number generators. </p>
<p>Initially, computers were quite basic compared to today’s sophisticated machines. Essentially, a computer operates on a strict set of instructions :  it cannot spontaneously generate a number as humans might randomly choose a number from 1 to 10.</p>
<p>For a computer, generating a random number requires specific instructions. Today, this task has become straightforward in many programming languages through built-in functions. For example, in C#, you can generate a random number between 1 and 10 with this simple command:</p>
<pre><code class="lang-c#">Random.Next(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>) <span class="hljs-comment">// &lt;-- Generates a radom number from 1 to 10</span>
</code></pre>
<p>The interesting part begins when we look under the hood.</p>
<h3 id="heading-simple-random-number-generator">Simple random number generator</h3>
<p>What if you were given a task to create a function that generates a random number? Let’s say you have this function:</p>
<pre><code class="lang-c#"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">GenerateRandomNumber</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> start, <span class="hljs-keyword">int</span> end</span>)</span>
{
  <span class="hljs-keyword">return</span> ✨🪄 magic ✨🪄
}
</code></pre>
<p>One of the simplest ways to do this is using a Linear Congruential Generator (LCG). The example below is a simplistic approach and you shouldn't use it for cryptographic purposes or applications requiring high levels of randomness.</p>
<pre><code class="lang-c#"><span class="hljs-keyword">using</span> System;

<span class="hljs-keyword">class</span> <span class="hljs-title">SimpleRandomGenerator</span>
{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> seed;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">long</span> a = <span class="hljs-number">25214903917</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">long</span> c = <span class="hljs-number">11</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> m = (<span class="hljs-keyword">long</span>)Math.Pow(<span class="hljs-number">2</span>, <span class="hljs-number">48</span>);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">SimpleRandomGenerator</span>(<span class="hljs-params"><span class="hljs-keyword">long</span> seed</span>)</span>
    {
        <span class="hljs-keyword">this</span>.seed = seed;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">Next</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> min, <span class="hljs-keyword">int</span> max</span>)</span>
    {
        <span class="hljs-comment">// Update the seed</span>
        seed = (a * seed + c) % m;

        <span class="hljs-comment">// Ensure the result is within the bounds [min, max)</span>
        <span class="hljs-keyword">int</span> result = (<span class="hljs-keyword">int</span>)(min + (seed % (max - min)));
        <span class="hljs-keyword">return</span> result;
    }
}

<span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
    {
        <span class="hljs-keyword">var</span> generator = <span class="hljs-keyword">new</span> SimpleRandomGenerator(DateTime.Now.Ticks);

        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">15</span>; i++)
        {
            <span class="hljs-keyword">var</span> rndNumber = generator.Next(<span class="hljs-number">1</span>, <span class="hljs-number">101</span>);

            Console.WriteLine(<span class="hljs-string">$"Random number between 1 and 100: <span class="hljs-subst">{rndNumber}</span>"</span>);        
        }
    }
}

<span class="hljs-comment">/* Output
Random number between 1 and 100: 78
Random number between 1 and 100: 9
Random number between 1 and 100: -48
Random number between 1 and 100: 71
Random number between 1 and 100: 6
Random number between 1 and 100: 45
Random number between 1 and 100: 64
Random number between 1 and 100: 99
Random number between 1 and 100: -34
Random number between 1 and 100: 85
Random number between 1 and 100: -44
Random number between 1 and 100: -25
Random number between 1 and 100: 26
Random number between 1 and 100: -27
Random number between 1 and 100: 24
*/</span>
</code></pre>
<p>This example uses the <a target="_blank" href="https://www.geeksforgeeks.org/linear-congruence-method-for-generating-pseudo-random-numbers/">Linear Congruential Generator</a> (LCG) method, which is a basic pseudorandom number generator. </p>
<p>LCGs are one of the oldest and simplest methods for generating sequences of pseudo-random numbers, and they operate based on a simple mathematical formula: "<em>new seed = (a×seed+c) mod m" .</em> The seed is typically initialized using a value with sufficient entropy, such as the current time (<code>DateTime.Now.Ticks</code> in this case). The <code>Next</code> method generates a new "random" number within the specified range [min, max). </p>
<p>Here's the step-by-step logic:</p>
<ol>
<li><strong>Update the Seed</strong>: The seed is updated using the LCG formula mentioned above. This step is critical, as it uses the old seed to produce a new one, ensuring that each call to <code>Next</code> results in a different output.</li>
<li><strong>Scaling the Output</strong>: Once the new seed is calculated, it needs to be adjusted to fall within the user-specified range <code>[min, max)</code>.<br>– The modulus operation <code>seed % (max - min)</code> scales the seed to a value within the range of 0 to <code>(max - min) - 1</code>.<br>– Adding <code>min</code> shifts this scaled value into the desired range, ensuring that the result is at least <code>min</code> but less than <code>max</code>.</li>
</ol>
<h2 id="heading-true-random-number-generation-trng-and-entropy-sources">True Random Number Generation (TRNG) and Entropy Sources</h2>
<p>Random number generation based on natural events or hardware characteristics involves using unpredictable, non-deterministic sources to generate randomness. This approach is often referred to as using "entropy sources" or "true random number generation" (TRNG). </p>
<p>Unlike pseudo-random number generators (PRNGs) that use mathematical algorithms and require a seed value, true random number generators derive their randomness from physical events that are almost unpredictable. Here are a few examples:</p>
<h3 id="heading-earthquakes-in-trng">Earthquakes in TRNG</h3>
<p>Earthquakes generate seismic data that is almost unpredictable and can be used as a source of randomness. By measuring seismic activity through geophones or seismographs, the minute variations in the Earth's movement can be converted into random numbers. </p>
<p>Earthquakes occur due to the sudden release of energy in the Earth's crust, resulting in the ground shaking. This energy release is unpredictable and varies in magnitude, location, and frequency. The unpredictability of the timing, duration, and intensity of seismic events makes this a viable entropy source.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-37.png" alt="Image" width="600" height="400" loading="lazy">
<em>[USGS Magnitude 2.5+ Earthquakes data, Past Day](https://earthquake.usgs.gov/earthquakes/map/?currentFeatureId=pr71446783&amp;extent=9.79568,-147.39258&amp;extent=58.99531,-42.62695" rel="noopener)</em></p>
<h4 id="heading-additional-technical-details">Additional technical details</h4>
<p>Here are some additional technical details about earthquakes in TRNG:</p>
<p>Data collection is typically done using instruments called seismometers or geophones, which are sensitive to ground vibrations. These devices convert the kinetic energy of ground movements into electrical signals that can then be digitized and analyzed. </p>
<p>This process might include:</p>
<ul>
<li><strong>Signal Conditioning and Filtering:</strong> Filtering the seismic signals to isolate the random components from predictable noise or background vibrations.</li>
<li><strong>Digitization:</strong> Converting the analog signals into digital values, which typically involves sampling the signal at regular intervals and quantizing these samples into digital values.</li>
</ul>
<p>The raw digital data derived from seismic activity might not be uniformly random due to natural biases in how earthquakes occur or how data is collected. </p>
<p>To ensure that the numbers generated are suitable for use in applications requiring high-quality randomness (such as cryptographic systems), further processing might be necessary. </p>
<p>Here are the common techniques:</p>
<ul>
<li><strong>Debiasing</strong>: Applying algorithms to remove any predictable patterns or biases from the data.</li>
<li><strong>Whitening</strong>: Transforming the data to ensure a uniform distribution across all possible values. This often involves statistical tests to adjust the output until it meets the criteria for randomness.</li>
</ul>
<p>Using earthquakes for random number generation could be particularly valuable in applications where an external, unpredictable source of randomness is beneficial. </p>
<p>But there are cons and practical considerations:</p>
<ul>
<li><strong>Geographical Limitations</strong>: Not all locations experience frequent seismic activity, which could limit the availability of this method to specific regions.</li>
<li><strong>Event Rarity</strong>: Significant seismic events are relatively rare and unpredictable in timing, which might not provide a steady or reliable source of randomness when needed.</li>
<li><strong>Data Collection and Processing Overhead:</strong> The infrastructure and computational effort required to capture, process, and utilize seismic data for random number generation can be significant.</li>
</ul>
<h3 id="heading-hardware-events-in-trng">Hardware Events in TRNG</h3>
<p>Hardware-based random number generators (HRNGs) use physical processes within computing devices to generate randomness. Examples include:</p>
<h4 id="heading-thermal-noise-johnson-nyquist-noise">Thermal Noise (Johnson-Nyquist Noise):</h4>
<p>Thermal noise, also known as Johnson-Nyquist noise, is a type of interference naturally present in all electronic devices and circuits. It’s caused by the random motion of electrons within a material due to heat. This phenomenon can be used as a source of randomness for generating random numbers in hardware devices.</p>
<p>Every material that conducts electricity has electrons, which are tiny particles that move around and carry electrical current. Even when a device isn’t actively being used, these electrons are never completely still – they move randomly because of the heat energy within the material. The higher the temperature, the more active the electrons become.</p>
<p>Thermal noise is generated by the inherent energy present in all materials at temperatures above absolute zero (-273.15°C or -459.67°F). At these temperatures, electrons gain energy and start moving randomly. This movement causes tiny, random fluctuations in the electrical current when measured across components like resistors.</p>
<p>Thermal noise is ideal for cryptographic applications where high security is essential. This includes key generation and secure communications where unpredictability is paramount to preventing attacks. </p>
<p>In developing secure communication protocols for applications like instant messaging, VoIP, or data transmission systems, thermal noise can be used to generate encryption keys that are nearly impossible to predict, enhancing security.</p>
<h4 id="heading-clock-drift">Clock Drift</h4>
<p>Clock drift occurs due to the slight and unpredictable variations in the timing mechanisms (like crystal oscillators) of computers and other digital devices. Clock drift exploits the natural variability in hardware clocks, which are designed to measure time but can drift apart due to minor differences in the frequency of their oscillators.</p>
<p>By comparing the time reported by two or more independent clocks, small differences that occur naturally and unpredictably can be measured. These differences are influenced by factors such as temperature changes, hardware imperfections, and supply voltage variations.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-38.png" alt="Image" width="600" height="400" loading="lazy">
_[A USB-pluggable hardware true random number generator](https://en.wikipedia.org/wiki/Hardware_random_number_generator#Clock<em>drift" rel="noopener)</em></p>
<h4 id="heading-photonic-emission">Photonic Emission</h4>
<p>Photonic emission-based random number generation uses the process of light emission to create random numbers. This approach relies on the quantum nature of light  – specifically, the behavior of photons, which are tiny particles that make up the light. </p>
<p>Photonic emission occurs when energy is released from atoms in the form of light. This happens in devices like LEDs (light-emitting diodes) and lasers. </p>
<p>In an LED, when electricity flows through the device, it excites electrons (tiny negatively charged particles) to higher energy states. As these electrons return to their normal states, they release energy in the form of photons. </p>
<p>The exact moment a photon is emitted is inherently unpredictable due to the principles of quantum mechanics, where particles like electrons behave in a probabilistic manner.</p>
<p>To turn photonic emission into random numbers, we first need to detect these photons. We can do this using a device called a photodetector, which captures the light and converts each photon hit into an electrical signal. </p>
<p>The key to randomness lies in the timing of each photon’s arrival at the detector. Since the emission of each photon is random, the times they are detected are also random. These times are then recorded with high precision.</p>
<h4 id="heading-cloudflares-lava-lamps-for-randomness">Cloudflare’s Lava Lamps for Randomness</h4>
<p>Cloudflare, a web performance and security company, has set up a wall of lava lamps in the lobby of their San Francisco office. The setup is known as the “LavaRand” system. It leverages the unpredictable and ever-changing movements of the “lava” inside these lamps to generate randomness.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-39.png" alt="Image" width="600" height="400" loading="lazy">
<em>Cloudflare’s Lava Lamps. The view from the camera</em></p>
<p><strong>How LavaRand Works:</strong><br>The process starts with visual capturing. A camera is pointed at the wall of lava lamps. The lamps contain blobs of wax in a liquid that expand and move in unpredictable ways when heated. </p>
<p>As the wax heats up, it rises, and as it cools, it falls, creating an ever-changing, visually chaotic display. </p>
<p>The camera takes images of the lava lamps at regular intervals. Each image captures a unique, random pattern of swirling wax. These images are then processed using computer algorithms to extract random data from the patterns observed in the images.</p>
<p><strong>Relation to Photonic Emission:</strong><br>While Cloudflare’s Lava Lamps use a form of photonic emission, it’s indirect. The photonic emission in this context is the light emitted by the lamps, which illuminates the wax inside. </p>
<p>The random number generation process, however, primarily relies on the chaotic physical movements of the wax, which are captured by the light and recorded by a camera. The randomness comes from how the light and shadows play off the moving lava, rather than the emission and detection of photons at a quantum level (which is more typical in photonic emission RNG systems using LEDs or lasers).</p>
<p><strong>Information from Cloudflare's official website:</strong></p>
<blockquote>
<p>LavaRand is a system that uses lava lamps as a secondary source of randomness for our production servers. A wall of lava lamps in the lobby of our San Francisco office provides an unpredictable input to a camera aimed at the wall. A video feed from the camera is fed into a CSPRNG, and that CSPRNG provides a stream of random values that can be used as an extra source of randomness by our production servers. Since the flow of the “lava” in a lava lamp is very unpredictable,1 “measuring” the lamps by taking footage of them is a good way to obtain unpredictable randomness. Computers store images as very large numbers, so we can use them as the input to a CSPRNG just like any other number.  </p>
<p>We’re not the first ones to do this. Our LavaRand system was inspired by a similar system first <a target="_blank" href="https://en.wikipedia.org/wiki/Lavarand">proposed and built</a> by Silicon Graphics and <a target="_blank" href="https://www.google.com/patents/US5732138">patented</a> in 1996 (the patent has since expired).  </p>
<p>Hopefully, we’ll never need it. Hopefully, the primary sources of randomness used by our production servers will remain secure, and LavaRand will serve little purpose beyond adding some flair to our office. But if it turns out that we’re wrong, and that our randomness sources in production are actually flawed, then LavaRand will be our hedge, making it just a little bit harder to hack Cloudflare.   </p>
<p>Read more <a target="_blank" href="https://blog.cloudflare.com/randomness-101-lavarand-in-production">here</a>.</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-40.png" alt="Image" width="600" height="400" loading="lazy">
<em>[First proposed and patented LavaLend in 1996](https://patents.google.com/patent/US5732138" rel="noopener)</em></p>
<h3 id="heading-human-factors-in-trng">Human Factors in TRNG</h3>
<h4 id="heading-mouseware">Mouseware</h4>
<p>Some tools like <a target="_blank" href="https://www.mouseware.org/">Mouseware</a> use human factors to generate randomness. Mouseware uses a cryptographically secure random number generator based on your mouse movements to generate secure, memorable passwords. Passwords are generated entirely in the browser, and no data is ever sent over the network. </p>
<p>For those generated passwords, it would take 22400.7 years to guess at 1000 guesses/second and 2.0 hours to guess at 100 billion guesses/second.</p>
<ul>
<li>1000 guesses/second is a worst-case web-based attack. Typically this is the only type of attack feasible against a secure website.</li>
<li>100 billion guesses/second is a worst-case offline attack when a hashed password database is stolen by someone with nontrivial technical and financial resources.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Screen-Recording-2024-04-27-at-22.02.43.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Example of the flow to generate random numbers based on mouse movements</em></p>
<p>You can <a target="_blank" href="https://www.mouseware.org/">read more about Mouseware</a> on their website.</p>
<h2 id="heading-randomness-in-software-testing">Randomness in Software Testing</h2>
<h3 id="heading-chaos-monkey-developed-my-netflix">Chaos Monkey developed my Netflix</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-7.png" alt="Image" width="600" height="400" loading="lazy">
<em>Chaos Monkey</em></p>
<p>Chaos Monkey is an innovative tool developed by Netflix. It's responsible for randomly terminating Netflix's instances in <em>production</em> to ensure that engineers implement their services to be resilient to instance failures. </p>
<p>Imagine a virtual, mischievous monkey randomly tinkering with the network—shutting down instances, disconnecting servers, or overloading systems to simulate possible failures. </p>
<p>Although it might seem counterintuitive, the purpose of Chaos Monkey is to proactively provoke controlled failures. This strategy allows Netflix's engineers to test how well their systems can handle unexpected disruptions. The aim is to identify and resolve weaknesses before they impact users, ensuring that the infrastructure is robust enough to withstand real-world issues.</p>
<p>For instance, if Chaos Monkey randomly terminates a server and everything continues to run smoothly, that’s a win. If problems arise, engineers quickly analyze and rectify them, thereby strengthening the system. This continuous testing and improvement cycle helps ensure that when you settle in to binge-watch your favorite series, you experience uninterrupted streaming.</p>
<p>Thanks to tools like Chaos Monkey and the principles of Chaos Engineering, Netflix can deliver a seamless viewing experience. Next time you watch a show without any glitches, remember the behind-the-scenes efforts of these unsung heroes keeping your entertainment flawless.</p>
<p>This tool is also available for open source usage. <a target="_blank" href="https://netflix.github.io/chaosmonkey/">Check out the docs here</a>. </p>
<h2 id="heading-randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</h2>
<p>Randomness plays a critical role in cryptographic systems, forming the backbone of security protocols across the digital landscape. This section explores why randomness is essential in cryptography, how it is generated, and the challenges involved in ensuring its effectiveness. </p>
<p>In cryptographic systems, randomness is used to generate keys, initialize cryptographic algorithms, and for non-repudiation processes like digital signatures and secure communications. </p>
<p>The strength and security of almost all cryptographic techniques depend on the quality of the randomness used. If the randomness is predictable, so too are the cryptographic keys, making the system vulnerable to attacks.</p>
<p>If we encrypt the text “<code>Hello World</code>”, we will get this text “<code>oO64D2IzNWKSQnDM8fcZ/w==</code>”. To see the power of encryption, let’s also encrypt variations of the text: “HelloWorld” (without a space) and “Hello world” (with lowercase), while also experimenting with a different encryption key. </p>
<p>Here are the outcomes:</p>
<pre><code class="lang-text">╔═════════════╦═══════════╦══════════════════════════╗
║    Text     ║ Password  ║      Encoded value       ║
╠═════════════╬═══════════╬══════════════════════════╣
║ Hello World ║      1234 ║ oO64D2IzNWKSQnDM8fcZ/w== ║
╠─────────────╬───────────╬──────────────────────────╣
║ HelloWorld  ║      1234 ║ KvqAEHQhP9iBdFWhOUcYVg== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello world ║      1234 ║ jdKRaAw9ULCFb627e3mNpQ== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello World ║       123 ║ S/eGTyDQsgLwcEIrCWUAJw== ║
╠─────────────╬───────────╬──────────────────────────╣
║ HelloWorld  ║       123 ║ /JRa5+mllydL/F0m7NuxYA== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello world ║       123 ║ s3AydwlvlgHCcpiAhaurXg== ║
╚═════════════╩═══════════╩══════════════════════════╝
</code></pre>
<p>If you consider the above table, you’ll notice that even a small change, such as a change in spacing or a single character, leads to a complete transformation of the encrypted text. </p>
<p>This means that if the intruder manages to obtain both the original text and its encrypted form, they would still face a significant challenge in trying to guess the password required to unlock the entire database.</p>
<h3 id="heading-could-you-hack-the-encryption">Could you hack the encryption?</h3>
<p>Brute force attacks are a straightforward yet powerful method used by attackers to crack passwords and encryption keys. </p>
<p>A brute force attack involves systematically checking <strong>all possible combinations</strong> until the correct one is found. Attackers use brute force methods to try every possible key or password until they decrypt the targeted data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-6.png" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.imperva.com/learn/application-security/brute-force-attack/">Ream more about brute force attacks</a></em></p>
<p>In our case, for decrypting the word we will need to try every possible combination (even like a, aa, b, bb strings and so on).</p>
<p>Now lets calculate how much time is needed to decrypt/check every possible combination for our password. Suppose you own an exceptionally powerful supercomputer, coupled with cutting-edge technology and virtually unlimited resources. </p>
<p>Let’s say the computer has a whopping 1 terabyte (TB) of RAM allowing it to handle lots of tasks at once. For the CPU, this supercomputer boasts a mind-boggling speed of 1 exaflop, which means it can do about 1 quintillion calculations in just one second. 1 exaflop is equal to 1,000,000 gigaflops. So, to achieve 1 exaflop of computing power using Intel i9 processors with a performance of 300 gigaflops each, you would need 1,000,000 gigaflops / 300 gigaflops = 3,333,333 Intel i9 processors. </p>
<p>This hypothetical supercomputer, performing mind-blowing calculations at lightning speed, could do a brute-force attack on an encryption algorithm.</p>
<p>If our hypothetical supercomputer were to attempt every possible combination of text to decipher the encrypted data, it would be faced with an astronomical number of possibilities — ²²⁵⁶. It’s estimated that it would take not just years, not even centuries, <strong>but potentially tens of thousands of decades.</strong> </p>
<p>To read more about this, you can <a target="_blank" href="https://gor-grigoryan.medium.com/encryption-and-data-security-in-clean-architecture-using-ef-core-value-converters-a-guide-to-911711a1ec52">refer to this article that I wrote</a>.</p>
<h2 id="heading-randomness-in-simulation-and-modeling">Randomness in Simulation and Modeling</h2>
<h3 id="heading-monte-carlo-simulation">Monte Carlo Simulation</h3>
<p>The Monte Carlo Simulation is a mathematical technique used to understand the impact of risk and uncertainty in prediction and forecasting models. Essentially, it’s a method used to predict the probability of different outcomes when the intervention of random variables is present. </p>
<p>Named after the famous Monte Carlo Casino due to its reliance on randomness, this method is widely used across finance, engineering, research, and more.</p>
<p>In the context of finance, Monte Carlo simulation is commonly used to assess the risk and value of financial instruments, such as options or portfolios. By generating a large number of random scenarios for different input variables, such as asset prices or interest rates, Monte Carlo simulation can provide a range of possible outcomes and their associated probabilities. This method is mostly used when there is no analytical solution for the given problem.</p>
<p>Telecoms use them to assess network performance in various scenarios, which helps them to optimize their networks. Financial analysts use Monte Carlo simulations to assess the risk that an entity will default, and to analyze derivatives such as options. Insurers and oil well drillers also use them to measure risk. </p>
<p>To read more, <a target="_blank" href="https://www.investopedia.com/terms/m/montecarlosimulation.asp">check out this article</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-41.png" alt="Image" width="600" height="400" loading="lazy">
<em>Monte Carlo Simulation Output of a Stock price. Retrieved from <a target="_blank" href="https://medium.com/@rmenghani21/computing-option-price-and-greeks-using-monte-carlo-simulation-21a3a24d11ba">this article</a></em></p>
<h2 id="heading-future-of-randomness-in-software-engineering">Future of Randomness in Software Engineering</h2>
<p>The future of randomness in software engineering looks particularly promising, with significant advancements expected from emerging technologies like quantum computing.</p>
<h3 id="heading-quantum-computing-and-quantum-randomness">Quantum Computing and Quantum Randomness</h3>
<p>Quantum computing introduces an inherently <a target="_blank" href="https://en.wikipedia.org/wiki/Stochastic">stochastic</a> element known as quantum randomness. </p>
<p>Unlike classical computing, which relies on deterministic processes, quantum processes are unpredictable by nature. Quantum random number generators (QRNGs) exploit this property to generate true random numbers directly from quantum phenomena, such as the superposition of quantum states or the measurement of entangled particles. </p>
<p>These devices are expected to provide a more secure and fundamentally unpredictable source of randomness than is currently possible.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-42.png" alt="Image" width="600" height="400" loading="lazy">
<em>IBM’s new 53-qubit quantum computer</em></p>
<p>Quantum computing has the potential to revolutionize cryptography. Current cryptographic systems rely on the computational difficulty of certain problems (like factoring large numbers) <strong>which quantum computers could solve effortlessly</strong>. But quantum cryptography, utilizing quantum randomness for key distribution, promises to be virtually unbreakable due to the laws of quantum mechanics.</p>
<h3 id="heading-current-state-of-quantum-computing">Current State of Quantum Computing</h3>
<p>As of now, quantum computing is in an experimental phase. Researchers and companies like Google, IBM, and D-Wave are actively developing quantum computers and have made significant progress in recent years. </p>
<p>For instance, Google announced "quantum supremacy" in 2019, claiming that their quantum computer solved a problem that would be practically impossible for a classical computer to solve in any reasonable amount of time. </p>
<p>Quantum bits, or qubits, which are the basic units of information in quantum computing, are highly susceptible to interference from their environment. This leads to high error rates in quantum computations. Developing error-correcting codes and finding ways to make qubits more stable is a significant focus of current research. </p>
<p>Currently, quantum computers have a limited number of qubits. To be practical for widespread use, quantum computers need to scale up the number of qubits significantly without a corresponding increase in error rates. </p>
<p>Also those computers need to operate at extremely low temperatures, close to absolute zero, to maintain the quantum state of the qubits. Maintaining such conditions is technically challenging and expensive.</p>
<p>The consensus among experts is cautiously optimistic, but varies widely regarding when quantum computing will become practical for broad use. </p>
<p>Some experts believe that within the next decade, we'll begin to see quantum computers solving more practical, real-world problems, potentially revolutionizing fields like cryptography, materials science, and complex system simulation. Others think that these applications might remain out of reach for <strong>several more decades</strong>.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>The future of randomness in software engineering holds vast potential to drive innovation across multiple domains. </p>
<p>As we delve deeper into quantum computing and enhance our current technologies, randomness will play an increasingly critical role in shaping the next generation of software solutions, making them more secure, efficient, and reflective of the complex world they model.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-8.png" alt="Image" width="600" height="400" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
