<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amnon Sadeh</title>
    <description>The latest articles on DEV Community by Amnon Sadeh (@targumon).</description>
    <link>https://dev.to/targumon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F195653%2Ffce04b12-e05b-416f-8062-aaba0b5b3cd9.jpeg</url>
      <title>DEV Community: Amnon Sadeh</title>
      <link>https://dev.to/targumon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/targumon"/>
    <language>en</language>
    <item>
      <title>Slack Netiquette and Best Practices</title>
      <dc:creator>Amnon Sadeh</dc:creator>
      <pubDate>Sun, 29 May 2022 14:50:24 +0000</pubDate>
      <link>https://dev.to/targumon/slack-netiquette-and-best-practices-1i67</link>
      <guid>https://dev.to/targumon/slack-netiquette-and-best-practices-1i67</guid>
      <description>&lt;h3&gt;
  
  
  Table of contents:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;No Hello 👋&lt;/li&gt;
&lt;li&gt;Less Messages ↩️&lt;/li&gt;
&lt;li&gt;Always* Reply in Thread 💬&lt;/li&gt;
&lt;li&gt;Channels Privacy 🔒&lt;/li&gt;
&lt;li&gt;#general 🆚 #random&lt;/li&gt;
&lt;li&gt;Be Generous with Emoji Reactions 🙂&lt;/li&gt;
&lt;li&gt;Add a Profile Photo 🧑‍🎤&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  No Hello 👋 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Slack is foremost async (as opposed to a phone call or a face to face meeting).&lt;br&gt;
So greeting "&lt;em&gt;Hi!&lt;/em&gt;" and waiting for someone to respond before actually asking your question is counterproductive for both of you.&lt;br&gt;
We're definitely not against politeness - just string both parts together, for example: "&lt;em&gt;Hola! Are we compliant with WCAG level A?&lt;/em&gt;"&lt;br&gt;
Learn more: &lt;a href="https://nohello.net/"&gt;https://nohello.net/&lt;/a&gt;, &lt;a href="https://nohello.club/"&gt;https://nohello.club/&lt;/a&gt;, &lt;a href="https://no-hello.com/"&gt;https://no-hello.com/&lt;/a&gt;...&lt;/p&gt;
&lt;h2&gt;
  
  
  Less Messages ↩️ &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;When writing more than one paragraph, don't send them as separate messages.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a teeming chat, fragmented messages might get scattered around other members' messages, therefore harder to follow&lt;/li&gt;
&lt;li&gt;Someone might not notice you're still typing and ask you a question regarding your first paragraph which you're already about to answer in the second one&lt;/li&gt;
&lt;li&gt;Fragmented messages cause unnecessary notifications (and some of us would rather not mute certain channels)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Either press &lt;code&gt;shift-Enter&lt;/code&gt; to start a new line within the same message&lt;/li&gt;
&lt;li&gt;Or better yet, change your preferences so plain &lt;code&gt;Enter&lt;/code&gt; &lt;em&gt;always&lt;/em&gt; starts a new line
(and use &lt;code&gt;⌘-Enter&lt;/code&gt; (Mac) or &lt;code&gt;ctrl-Enter&lt;/code&gt; (Windows) to send)
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o65xA52i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2sxle33bo8r0n5ny6w9u.png" alt="In Slack preferences you can set what pressing Enter does" width="880" height="598"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Always* Reply in Thread 💬 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;👎 Replying in a 'main' message triggers a notification for all channel members.&lt;/p&gt;

&lt;p&gt;👍 Replying in a thread triggers a notification only for members who also replied to it.&lt;/p&gt;

&lt;p&gt;This not only reduces noise, but also allows for better organized discussions.&lt;/p&gt;

&lt;p&gt;(* it's less of an issue in a direct chat with someone)&lt;/p&gt;
&lt;h2&gt;
  
  
  Channels Privacy 🔒 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;When creating a new channel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;strong&gt;sensitive&lt;/strong&gt; information will be discussed in it (anything that relates to customers, investors, prospect employees, etc.) - set it to &lt;strong&gt;private&lt;/strong&gt;. If in doubt - set it to &lt;strong&gt;private&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Only if no such information will be discussed (book club, basketball team, lan party, etc.) - it's probably okay to leave it as &lt;strong&gt;public&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While we're on this subject: don't discuss sensitive information via WhatsApp.&lt;/p&gt;
&lt;h2&gt;
  
  
  #general 🆚 #random &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The #general channel is meant for company-wide announcements (e.g. "&lt;em&gt;There's an electricity maintenance at the office at 19:00&lt;/em&gt;", "&lt;em&gt;Next month we're hosting a meetup - save the date!&lt;/em&gt;", and so on).&lt;/p&gt;

&lt;p&gt;#general is the only channel you &lt;em&gt;cannot&lt;/em&gt; leave. Once the company gets big enough, we might restrict who can post to it.&lt;/p&gt;

&lt;p&gt;On the other hand, the #random channel is the digital equivalent of a water cooler conversation - meant for casual stuff, non-work related, nerdy humor, etc.&lt;/p&gt;
&lt;h2&gt;
  
  
  Be Generous with Emoji Reactions 🙂 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In 2014 Slack added 'read receipts' (arguably their most requested feature) to their backlog:&lt;br&gt;
&lt;/p&gt;
&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--oVQ9rrFA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1461144163789983748/N5iAWd2d_normal.jpg" alt="Slack profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Slack
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @slackhq
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      &lt;a href="https://twitter.com/hermansje"&gt;@hermansje&lt;/a&gt; @svencharleer Planning on something like read receipts. 🎉 Thank you for the kind words! (And welcome @svencharleer)
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      23:20 PM - 26 Aug 2014
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=504407968150851585" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=504407968150851585" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=504407968150851585" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;Year after year, they kept postponing it. Until 2018 when they actively decided against it:&lt;br&gt;
&lt;/p&gt;
&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--oVQ9rrFA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1461144163789983748/N5iAWd2d_normal.jpg" alt="Slack profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Slack
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @slackhq
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      &lt;a href="https://twitter.com/godismyjudge95"&gt;@godismyjudge95&lt;/a&gt; We decided against adding read receipts, but many people use emoji reactions on messages as a sort of voluntary (and, dare we say, more fun) version of a read receipt. 🐝
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      22:55 PM - 09 Oct 2018
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1049795604166127616" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1049795604166127616" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1049795604166127616" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;So if you read a message like "&lt;em&gt;Today's all-hands meeting will be held 30 minutes earlier&lt;/em&gt;", nobody can tell whether you read it or not, so it's a good citizenship to react with an emoji (👍, 👌, etc.) to signal you actually did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add a Profile Photo 🧑‍🎤 &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Slack’s default avatars are... uninspiring:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sKMsZ_81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgx6jjki6ltf709l1p5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sKMsZ_81--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dgx6jjki6ltf709l1p5k.png" alt="Unidentified person silhouette" width="48" height="48"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b5yi1wCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cm1s9ci11ld42pdk44n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b5yi1wCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cm1s9ci11ld42pdk44n.png" alt="First letter of name" width="48" height="48"&gt;&lt;/a&gt; &lt;br&gt;
An actual photo is great, but any picture can add a personal touch and will help everyone with the #1 general netiquette rule: remember the human.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ESLy8j1E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su1a8j1fulgr7bx374rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ESLy8j1E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su1a8j1fulgr7bx374rb.png" alt="Amnon's avatar" width="48" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How does Math.random() work?</title>
      <dc:creator>Amnon Sadeh</dc:creator>
      <pubDate>Mon, 13 Jan 2020 21:30:32 +0000</pubDate>
      <link>https://dev.to/targumon/how-does-math-random-work-1526</link>
      <guid>https://dev.to/targumon/how-does-math-random-work-1526</guid>
      <description>&lt;h2&gt;
  
  
  Prolonged Prologue
&lt;/h2&gt;

&lt;p&gt;Recently I worked on a stateless server. In other words, if and when it sends a second response to a client, it has no context of the first one.&lt;/p&gt;

&lt;p&gt;Such backend code is pretty great – simple, clean, and easily testable.&lt;/p&gt;

&lt;p&gt;Auditing or debugging? Not so great. Within a certain timeframe the backend may serve many clients and though there's enough information to reconstruct which response originated from which client, we're lazy and just wanted to "color" them for quick identification.&lt;/p&gt;

&lt;p&gt;We decided to make the frontend generate a (pseudo-)random string when starting-up and send it with each request. No need for a convoluted UUID or something similar. Just plain ol' &lt;code&gt;Math.random().toString(36).slice(2)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fat Chance
&lt;/h2&gt;

&lt;p&gt;During code review I explained to my colleague that 99.9% of the time it will make our lives easier and the 0.1% chance of 2 clients generating the same string is no big deal, because as explained, we can still distinguish between them like we did before.&lt;/p&gt;

&lt;p&gt;She approved by change, got up, and as she walked away she pondered aloud &lt;em&gt;&lt;q&gt;But it's not really 0.1%, is it? Would be nice to figure out the &lt;strong&gt;actual&lt;/strong&gt; chance of collision&lt;/q&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Down the Rabbit Hole
&lt;/h2&gt;

&lt;p&gt;I knew &lt;code&gt;Math.random&lt;/code&gt; returns numbers between 0 (inclusive) and 1 (exclusive) with roughly equal probabilities across that range, I wasn't sure however &lt;em&gt;how&lt;/em&gt; it does that.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First stop – MDN of course! &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random"&gt;Their documentation for Math.random&lt;/a&gt; informed me that &lt;em&gt;&lt;q&gt;numbers in JavaScript are IEEE 754 floating point numbers&lt;/q&gt;&lt;/em&gt;. IEEE 754? What's that about exactly?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Second stop – ECMAScript Spec. &lt;a href="https://www.ecma-international.org/ecma-262/5.1/#sec-8.5"&gt;The Number type section&lt;/a&gt; revealed that IEEE 754 is just a fancy way of saying double-precision 64-bit floating-point number. Frankly, this is still too fancy, so I headed elsewhere.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Third stop – Wikipedia. &lt;a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format"&gt;The double-precision article&lt;/a&gt; threw me back to my CS degree with terms such as endianness and more importantly significand (AKA mantissa).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The last two sources taught me that even though this format has 2&lt;sup&gt;64&lt;/sup&gt; possible values (duh!), reserving 3 of them to represent &lt;code&gt;-0&lt;/code&gt; (which is different from &lt;code&gt;0&lt;/code&gt;, mind you), &lt;code&gt;infinity&lt;/code&gt;, and &lt;code&gt;-infinity&lt;/code&gt;, is pocket change relative to the 2&lt;sup&gt;53&lt;/sup&gt; &lt;code&gt;NaN&lt;/code&gt; values. Yep, you read that right: given arbitrary sets of 64 bits, if you ask &lt;em&gt;&lt;q&gt;what number does this represent?&lt;/q&gt;&lt;/em&gt;, 1 out of 2048 times the answer will be &lt;em&gt;&lt;q&gt;it's &lt;strong&gt;not&lt;/strong&gt; a number&lt;/q&gt;&lt;/em&gt;. 🤯 #MindBlown&lt;/li&gt;
&lt;li&gt;Speaking of possible values, every non-zero number can take the shape of &lt;code&gt;± 2ⁿ × 1.something&lt;/code&gt;. For example 2020, the current year, is &lt;code&gt;2¹⁰ × 1.97265625&lt;/code&gt;. The benefit here is that the "1." part can be assumed and doesn't need to be stored. Thus the significand has an extra bit – making the number a &lt;em&gt;bit&lt;/em&gt; more precise. 😂 #DadJokes&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this stage I stopped reading in order to experiment what numbers can JavaScript store. The smallest one below &lt;code&gt;1&lt;/code&gt; turns out to be &lt;code&gt;0.9999999999999999&lt;/code&gt;. i.e. if you enter &lt;code&gt;0.99999999999999994&lt;/code&gt; in the console, JS will omit the last digit, and if you enter &lt;code&gt;0.99999999999999995&lt;/code&gt; it will just round up to &lt;code&gt;1&lt;/code&gt;.&lt;br&gt;
The next numbers are:&lt;br&gt;
&lt;code&gt;0.9999999999999998&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999997&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999996&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999994&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999993&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999992&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.9999999999999991&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.999999999999999&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0.9999999999999995&lt;/code&gt; is not absent by mistake. Remember these numbers are displayed as decimals, but are binary under the hood. Expect rounding errors when "translating" back and forth.&lt;/p&gt;

&lt;p&gt;Naïvely I thought, &lt;em&gt;&lt;q&gt;Well, if I continue with these small decrements, after about 10 quadrillion times, it will go down to &lt;code&gt;0.0000000000000001&lt;/code&gt;&lt;/q&gt;&lt;/em&gt;. I immediately realized this misses the whole point of floating-point! 😂 #DadJokes&lt;/p&gt;

&lt;p&gt;It's not the end. From there, we can &lt;strong&gt;again&lt;/strong&gt; decrement 10 quadrillion times&lt;br&gt;
&lt;code&gt;0.00000000000000009999999999999999&lt;/code&gt;&lt;br&gt;
&lt;code&gt;0.00000000000000009999999999999997&lt;/code&gt;&lt;br&gt;
down to&lt;br&gt;
&lt;code&gt;0.00000000000000000000000000000001&lt;/code&gt;&lt;br&gt;
and so on.&lt;/p&gt;

&lt;p&gt;This revelation – the density increases towards 0 – is in fact tied to the &lt;a href="https://www.google.com/search?q=subnormal+numbers"&gt;subnormal numbers&lt;/a&gt; (that "1.something" from before? for them it's actually "0.something").&lt;/p&gt;

&lt;p&gt;I'm dwelling on this because &lt;code&gt;Math.random&lt;/code&gt; is supposed to return values with approximately uniform distribution. This means the set of its possible results is &lt;strong&gt;smaller&lt;/strong&gt; than the general set of numbers JS can represent in the range [0,1). Or looking at it the other way around: there are fractions that you can set yourself, but can never get from &lt;code&gt;Math.random&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back on Track
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Penultimate stop – &lt;a href="https://v8.dev/blog/math-random"&gt;The V8 blog&lt;/a&gt; explained how about 4 years ago &lt;code&gt;Math.random&lt;/code&gt; switched to use the &lt;code&gt;xorshift128+&lt;/code&gt; algorithm (noting other major browsers switched to it as well). This is &lt;em&gt;almost&lt;/em&gt; what I was looking for – as this algorithm deals with generating &lt;code&gt;integer&lt;/code&gt; numbers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Final stop – &lt;a href="https://github.com/v8/v8/blob/52f88e1b937a46cb39087149a76615ced7e539f0/src/base/utils/random-number-generator.h#L111"&gt;The glorious V8 source code&lt;/a&gt; unveiled how it's done (I believe other engines behave similarly): &lt;code&gt;ToDouble&lt;/code&gt; takes the latest generated integer, right-shifts it into what would shortly become the significand, sets the exponent to &lt;code&gt;0x3FF&lt;/code&gt; (which means &lt;code&gt;+2⁰&lt;/code&gt;) and casts it to &lt;code&gt;double&lt;/code&gt;. This yields &lt;code&gt;2⁰ × 1.random&lt;/code&gt; and the only thing left to do is subtract &lt;code&gt;1&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kr"&gt;inline&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;ToDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint64_t&lt;/span&gt; &lt;span class="n"&gt;state0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Exponent for double values for [1.0 .. 2.0)&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;uint64_t&lt;/span&gt; &lt;span class="n"&gt;kExponentBits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;uint64_t&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mh"&gt;0x3FF0000000000000&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="kt"&gt;uint64_t&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state0&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;kExponentBits&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;bit_cast&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Answer to the Ultimate Question
&lt;/h2&gt;

&lt;p&gt;There are 2⁵² (or 4,503,599,627,370,496) possible values for &lt;code&gt;Math.random&lt;/code&gt; to return. It &lt;em&gt;is&lt;/em&gt; a few quadrillions after all!&lt;/p&gt;

&lt;p&gt;I plugged this value into the &lt;a href="https://en.wikipedia.org/wiki/Birthday_problem#Cast_as_a_collision_problem"&gt;general equation for the birthday paradox&lt;/a&gt; and was relieved to learn that even with thousands of simultaneously connected clients, we have better chance of winning the lottery than have a collision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Post Trauma
&lt;/h2&gt;

&lt;p&gt;I obviously called my colleague to share these findings with her. She nodded understandingly, then paused for a moment before remarking &lt;em&gt;&lt;q&gt;Good, now we also know the chance of an empty identifier&lt;/q&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To which I replied, &lt;em&gt;&lt;q&gt;Say what now?&lt;/q&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;q&gt;Yeah, there's 1 in 2⁵² chance to get any specific value from calling &lt;code&gt;Math.random()&lt;/code&gt; and one of those is 0. In that rare yet possible case &lt;code&gt;slice(2)&lt;/code&gt; will leave you with an empty string. Not that it matters too much – you said you wanted to "color" the traffic with a string. I guess &lt;strong&gt;transparent&lt;/strong&gt; is as good color as any&lt;/q&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;q&gt;I'm never asking for your code review again.&lt;/q&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;📟 Let me know if you ever use &lt;code&gt;Math.random()&lt;/code&gt; and get 0.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
