# Random level problem

**URL:** <https://forum.makecode.com/t/random-level-problem/34494>\
**Category:** Help\
**Created:** [March 12, 2025, 1:46am UTC](https://forum.makecode.com/t/random-level-problem/34494 "2025-03-12T01:46:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TVdaimon101](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/tvdaimon101/32/19664_2.png) [@TVdaimon101](https://forum.makecode.com/u/TVdaimon101)\
**Post date:** [March 12, 2025, 1:46am UTC](https://forum.makecode.com/t/random-level-problem/34494/1 "2025-03-12T01:46:22Z")

</div>

In [my game](https://makecode.com/_Hui70kaoeczV), I want the level order to randomize, but I don’t want the same level to appear twice. I tried using a list, but there is no “get and remove random value from list” block.

 ![Screenshot 2025-03-11 at 10.34.00 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/a/7/a7fe47f1c3879762164dddb09f3f79dbd5cb1144.png)  
Is there a way to get a random value and then remove it?

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [March 12, 2025, 2:21am UTC](https://forum.makecode.com/t/random-level-problem/34494/2 "2025-03-12T02:21:11Z")

</div>

( ( Level List ) get and remove value at ( pick random ( 0 ) to ( length of array ( ( Level List ) [-] ( 1 ) )

You just have to do the random part yourself!

---

<div class="post-metadata">

**Author:** ![DRay](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dray/32/20464_2.png) [@DRay](https://forum.makecode.com/u/DRay)\
**Post date:** [March 12, 2025, 2:22am UTC](https://forum.makecode.com/t/random-level-problem/34494/3 "2025-03-12T02:22:32Z")

</div>

Would this work?  
The ‘get and remove value at 0’ seems to be using an index to decide which element to to get and remove. So if you set the index as a random number between 0 and the length of the list, it seems like that get a random index within the range of indices.

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

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [March 12, 2025, 4:45pm UTC](https://forum.makecode.com/t/random-level-problem/34494/4 "2025-03-12T16:45:04Z")

</div>

@DRay yes but you need to subtract 1 from the length of the array (e.g. “pick random 0 to length of array list - 1”)

---

<div class="post-metadata">

**Author:** ![DRay](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dray/32/20464_2.png) [@DRay](https://forum.makecode.com/u/DRay)\
**Post date:** [March 12, 2025, 7:23pm UTC](https://forum.makecode.com/t/random-level-problem/34494/5 "2025-03-12T19:23:51Z")

</div>

Ah, good catch. The 0 indexing means that the length of the list will be 1 more than your index range because the indices start with 0 instead of 1.

---

<div class="post-metadata">

**Author:** ![TVdaimon101](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/tvdaimon101/32/19664_2.png) [@TVdaimon101](https://forum.makecode.com/u/TVdaimon101)\
**Post date:** [March 13, 2025, 10:15pm UTC](https://forum.makecode.com/t/random-level-problem/34494/6 "2025-03-13T22:15:34Z")

</div>

Thank you all. You were all a big help!
