-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|642|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Generators


 
Pakz
Created : 16 July 2019
 
Language : Monkey2

Random Bag

Get more predictable numbers

Latest Update

When you have a RPG you might want to get a more logical draw of numbers. A random bag is a list where you store(insert) numbers that you take out. A number for sword damage for instance.

In this example I created a stack where I store 20 numbers in ranging from 1 to 4. More 1's and less 4's. I then created a array which I fill with 20 numbers that were taken from the bag. These are drawn to the screen.

In the bag there are 20 numbers. When one is taken out there are 19 remaining. When the list is empty it gets refilled.

I got the idea from a streamer on youtube who was talking about this. (gixg17)

 

Comments


Tuesday, 16 July 2019, 03:33
Jayenkai
Yes, for a lot of Gamey things, it's generally better to fill a "bag" with items, then pluck from that, than doing a completely random event.

Things like Tetris can be frustrating if there's never a long bar. Instead, fill a bag with about 4 of each of all the shapes, then pluck from there.
Scrabble obviously needs this, and power-up drops, decks of cards, things like that.

On the other hand, rolling dice, flipping coins, etc.. those definitely prefer complete randomness.

I tend to fill an array, then randomise the order, then pluck from the end of the array.

A simple shuffle function.