<?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: Vyse</title>
    <description>The latest articles on DEV Community by Vyse (@vyse).</description>
    <link>https://dev.to/vyse</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1770099%2F1f113617-0673-47b3-9873-cdf57134eff3.gif</url>
      <title>DEV Community: Vyse</title>
      <link>https://dev.to/vyse</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vyse"/>
    <language>en</language>
    <item>
      <title>1 in X Probability Multiplier</title>
      <dc:creator>Vyse</dc:creator>
      <pubDate>Fri, 12 Jul 2024 07:27:43 +0000</pubDate>
      <link>https://dev.to/vyse/1-in-x-probability-multiplier-1c85</link>
      <guid>https://dev.to/vyse/1-in-x-probability-multiplier-1c85</guid>
      <description>&lt;p&gt;I'm trying to make a 1 in X probability system, but for some reason the multiplier isn't working. I gave myself a high multiplier and I'm still getting common blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const blocks_rng = [
  { name: "Dirt Block", item: "dirt", chance: 2 },
  { name: "Farmland", item: "farmland", chance: 3 },
  { name: "Oak Log", item: "oak_log", chance: 4 },
  { name: "Andesite", item: "andesite", chance: 6 },
  { name: "Granite", item: "granite", chance: 9 },
  { name: "Diorite", item: "diorite", chance: 12 },
  { name: "§9Stone", item: "stone", chance: 16 },
  { name: "§9Amethyst", item: "amethyst_block", chance: 32 },
  { name: "§9Magma", item: "magma", chance: 64 },
  { name: "§9Enchanting Table", item: "enchanting_table", chance: 128 },
  { name: "§9Mob Spawner", item: "mob_spawner", chance: 250 },
  { name: "§9Obsidian", item: "obsidian", chance: 512 },
  { name: "§dCrying Obsidian", item: "crying_obsidian", chance: 1024 },
  { name: "§dBeacon", item: "beacon", chance: 8024 },
  { name: "§dEnd Frame", item: "end_portal_frame", chance: 2500 },
  { name: "§dBedrock", item: "bedrock", chance: 5000 },
  { name: "§5Command Block", item: "command_block", chance: 10000 },
  { name: "§5Chain Command Block", item: "chain_command_block", chance: 25000 },
  { name: "§5Repeating Command Block", item: "repeating_command_block", chance: 30000 },
  { name: "§4§l§k!§4§l???§r§4§l§k!", item: "stone", chance: 999999999 }
];

function getRandomBlock() {
  const mult = 20;
  const scaledChances = blocks_rng.map(block =&amp;gt; mult / block.chance);
  const totalScaledChance = scaledChances.reduce((sum, scaledChance) =&amp;gt; sum + scaledChance, 0);

  let random = Math.random() * totalScaledChance;
  for (let i = 0; i &amp;lt; blocks_rng.length; i++) {
    if (random &amp;lt; scaledChances[i]) {
      return blocks_rng[i];
    }
    random -= scaledChances[i];
  }

  return blocks_rng[blocks_rng.length - 1];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
