# Fast Random extension

**URL:** <https://forum.makecode.com/t/fast-random-extension/5365>\
**Category:** Show & Tell\
**Tags:** extension\
**Created:** [January 5, 2021, 9:34pm UTC](https://forum.makecode.com/t/fast-random-extension/5365 "2021-01-05T21:34:44Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [August 9, 2021, 5:18pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/21 "2021-08-09T17:18:43Z")

</div>

Sprite util:

> **[GitHub - jwunderl/arcade-sprite-util: A few utility functions for sprites](https://github.com/jwunderl/arcade-sprite-util)**
>
> A few utility functions for sprites. Contribute to jwunderl/arcade-sprite-util development by creating an account on GitHub.

Shader:

> **[GitHub - riknoll/arcade-shader: An arcade extension for shading things](https://github.com/riknoll/arcade-shader)**
>
> An arcade extension for shading things. Contribute to riknoll/arcade-shader development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Raed438](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/raed438/32/24469_2.png) [@Raed438](https://forum.makecode.com/u/Raed438)\
**Post date:** [August 23, 2021, 6:42pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/22 "2021-08-23T18:42:08Z")

</div>

Yes, So I Am Creating Raed 3 trailer

---

<div class="post-metadata">

**Author:** ![jedundon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedundon/32/4939_2.png) [@jedundon](https://forum.makecode.com/u/jedundon)\
**Post date:** [September 4, 2021, 4:39am UTC](https://forum.makecode.com/t/fast-random-extension/5365/23 "2021-09-04T04:39:01Z")

</div>

I’m helping my son create a Minecraft mod in MakeCode using Microsoft’s Code Connector. We’re creating a procedurally generated city. He asked about using seeds so he can save/share the most interesting cities that are generated. I assumed this would be easy but, well, obviously not since I’ve landed here.

Unfortunately while this extension works great for MakeCode Arcade, it doesn’t seem to work for MakeCode for Minecraft. @UnsignedArduino , do you have any idea how to get this to work in the Minecraft version of MakeCode? Really appreciate any insights/leads you can provide. Thanks!

> **[Microsoft MakeCode for Minecraft](https://minecraft.makecode.com/)**
>
> Minecraft Code Editor using Blocks or JavaScript

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [September 6, 2021, 10:11pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/24 "2021-09-06T22:11:42Z")

</div>

You can try making a new Minecraft MakeCode project in JavaScript as a new extension, make a new file, (call it something like `fast_random_blocks.ts`) and copy the code from [my fast\_random\_blocks.ts](https://github.com/UnsignedArduino/Fast-Random-Blocks/blob/master/fast_random_blocks.ts). Then save that as a GitHub project and that will be your extension to try. I would do this myself, but i dont have access to a computer right now.

Good luck on the city! If it works, please share pics! 🙂

---

<div class="post-metadata">

**Author:** ![omnisImperium](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/omnisimperium/32/2728_2.png) [@omnisImperium](https://forum.makecode.com/u/omnisImperium)\
**Post date:** [September 6, 2021, 10:13pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/25 "2021-09-06T22:13:37Z")

</div>

As the resident smol brain, I have no idea how any of this works. Can someone give me a brief explanation of sorts?

---

<div class="post-metadata">

**Author:** ![jedundon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jedundon/32/4939_2.png) [@jedundon](https://forum.makecode.com/u/jedundon)\
**Post date:** [September 6, 2021, 10:21pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/26 "2021-09-06T22:21:24Z")

</div>

After fighting to get @UnsignedArduino 's extension to work in MakeCode for Minecraft and failing, I’ve created a different extension which seems to work in any MakeCode environment, including MakeCode for Minecraft. It is based on the algorithm posted here: [https://stackoverflow.com/a/29450606](https://stackoverflow.com/a/29450606).

I _highly_ doubt it is as good as the Fast Random extension above. However, for anyone having trouble with that extension, I recommend taking a look at what I’ve put together.

Note: To use in Minecraft, you’ll need to import using a makecode-dot-com link as that editor doesn’t yet support Github. To do this, import into MakeCode Arcade as an extension and then use Share to publish that project. Import the makecode-dot-com link into MakeCode for Minecraft.

> **[GitHub - jedundon/makecode-pseudorandomnumbergenerator-blocks: A Pseudorandom...](https://github.com/jedundon/makecode-pseudorandomnumbergenerator-blocks)**
>
> A Pseudorandom Number Generator for MakeCode. Contribute to jedundon/makecode-pseudorandomnumbergenerator-blocks development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Raed438](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/raed438/32/24469_2.png) [@Raed438](https://forum.makecode.com/u/Raed438)\
**Post date:** [September 17, 2021, 3:20pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/27 "2021-09-17T15:20:32Z")

</div>

Working On Raed 1 (Still)

---

<div class="post-metadata">

**Author:** ![Raed438](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/raed438/32/24469_2.png) [@Raed438](https://forum.makecode.com/u/Raed438)\
**Post date:** [June 2, 2022, 4:06pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/28 "2022-06-02T16:06:25Z")

</div>

I am working on Baldi’s Basics In MakeCode, So Get Ready

---

<div class="post-metadata">

**Author:** ![slifox38](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/slifox38/32/18572_2.png) [@slifox38](https://forum.makecode.com/u/slifox38)\
**Post date:** [December 4, 2024, 9:34pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/30 "2024-12-04T21:34:30Z")

</div>

@UnsignedArduino How do i use this? Im trying to figure out how to make a infinite map for my runner but I can’t figure it out, please help.

---

<div class="post-metadata">

**Author:** ![MasonTheLitten](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/masonthelitten/32/24867_2.png) [@MasonTheLitten](https://forum.makecode.com/u/MasonTheLitten)\
**Post date:** [March 10, 2026, 8:35pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/31 "2026-03-10T20:35:42Z")

</div>

bumping this  
i need help as well,  
my school blocks the block help pages, so i come here for help on how to use blocks.  
specifically these three blocks

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/2/6/2632033da9cddbc49290aea2650d96476a505c8c.png)

And if i may, i want to request a detailed explaination on how to use all of the blocks in this extention in this topic for others sake too

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [March 11, 2026, 2:19am UTC](https://forum.makecode.com/t/fast-random-extension/5365/32 "2026-03-11T02:19:59Z")

</div>

the pick random from array of block accepts an array (you can drag out the array of block and replace it with a variable that has any type of array inside) and picks a random value from it. So if you have the array [1, 4, 5, 6, 7, 8] then it might pick 7.

the 50/50 and n percent chance block return a boolean (true or false), which is true approximately 50% and n% of the time respectively. for example, if you did rng 5% chance, out of 100 runs of that function, normally it will return 5 trues. (obviously, it is chance based, so it could return 6 trues out of 100, or 4, etc. see the binomial distribution)

Also, if you can access GitHub (which I doubt it because you said your school blocks the help pages) then you can read the source code which has comments: [https://github.com/UnsignedArduino/Fast-Random-Blocks/blob/master/fast\_random\_blocks.ts](https://github.com/UnsignedArduino/Fast-Random-Blocks/blob/master/fast_random_blocks.ts)

---

<div class="post-metadata">

**Author:** ![MasonTheLitten](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/masonthelitten/32/24867_2.png) [@MasonTheLitten](https://forum.makecode.com/u/MasonTheLitten)\
**Post date:** [March 11, 2026, 5:43pm UTC](https://forum.makecode.com/t/fast-random-extension/5365/33 "2026-03-11T17:43:40Z")

</div>

This clears up a lot of questions, but i have some new ones  
can i use the n% chance numbers as a set of chances?  
like, put them into the “Pick random from array of:” block. Will this make it pick random using the provided chances/. or will it ignore the chances and just pick a random block with no chances at all.  
I hope you can understand what im trying to explain- i have a hard time articulating  
i made this to try and show what i mean

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/b/8/b8fccd640f8a5991f940bbced494889c14bec672.png)

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [March 12, 2026, 2:21am UTC](https://forum.makecode.com/t/fast-random-extension/5365/34 "2026-03-12T02:21:10Z")

</div>

(ignoring the fact that the RNG object is not initialized, and is being set to the result) I’m sorry, I’m pretty confused by what you’re asking 😅. But this is what that code would do:

```ts
// TypeScript equivalent
const result = rng.randomElement([
  rng.percentChance(10),
  rng.percentChance(11),
  rng.percentChance(20),
  rng.percentChance(33),
  rng.percentChance(25),
  rng.percentChance(1)
]);

```

Firstly, those `rng.percentChance()` blocks all evaluate to a single boolean (True/False), so then the result could look like this:

```ts
const result = rng.randomElement([
  false,
  false,
  true,
  true,
  false,
  false
]);

```

Now the `rng.randomElement` block will pick one of those six booleans randomly, all with equal chance: So then, the result could look like this:

```ts
const result = false;

```

The percent chance blocks just return a single boolean at the time of execution. So if this statement was executed multiple times, you would get a different array of six booleans, and then `randomElement` would pick randomly from that array. The result is a boolean.

* * *

If you are asking about wanting to use a random percentage number, and THEN passing it to the n% chance block, you would want something like this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/e/c/ec354ae0a127d4861dae657a9cf65c77b60e8588.png)

This is what the above code would do:

```ts
//TypeScript equivalent
const result = rng.percentChance(
  rng.randomElement([10, 11, 20, 33, 25, 1])
);

```

Firstly, the `rng.randomElement` function picks a random number from that list, all having equal chance. So then it could look like this:

```ts
const result = rng.percentChance(
  11
);

```

Then the `rng.percentChance` will return a boolean, where the chance of getting True in this case would be 11% of the time. So then, the result could look like this:

```ts
const result = false;

```

[Previous page](https://forum.makecode.com/t/fast-random-extension/5365.md?page=1)
