Finely crafted video and tabletop games

Follow this page for updates, news, releases, game design thoughts, and shitposts.


itch.io page
dwoboyle.itch.io/
Personal Cohost Page
cohost.org/dwoboyle

posts from @Quixoneira tagged #random number generation

also:

Computers are good at faking randomness, but sometimes you want something to feel more random than it actually is. Old video games would often do clever things with using information that's in the RAM already to determine things that seem random. This allows players to exploit or manipulate the randomness if they're willing to do that. I always thought that was really cool and like to emulate that idea.

So what I do is when the game is initialized I create a list of the numbers 0 through 99 with five copies of each number. Then I shuffle the list based on a random seed like this:

	var seed = 13; //Default Seed
	rng_list = ds_list_create();
	repeat(5) for( var i = 0; i < 100; i++ ){
		ds_list_add(rng_list,i);
	}
	random_set_seed(seed);
	ds_list_shuffle(rng_list);

As you can see the default seed here is 13 (because it's my lucky number shhhh). This will always create a list of numbers in the same order.

Whenever I want to get something from the list I use an index variable. I have index variables for all sorts of things. Player attacks, enemy ai, boss ai, pick ups, etc, etc, etc! Every time I use one of those things I increase the index. This allows for different types of things to have variety but not affect each other. So you can't do things like shoot three times to make sure the RNG index is at a specific value so that an enemy behaves in a certain way.

Getting a number from the master list:

function rng(index){
	return ob_control.rng_list[| index];
}

A typical RNG function:

function rng_range(_low,_high,index){
	var _range = abs(_high-_low);
	var num = rng(index)/100;
	var results = _low+(_range * num);
	
	return results;
}

As you can see from rng_range I'm usually converting the number from the master rng list into a percentage. For example rng_range(0,100,1) would produce whatever value is at index 1 of the master list.

This let's there be a lot of control over RNG while still making it feel very random. I can even allow for different RNG styles or let players put in their own seeds if they want. It should make ever player satisfied.

if you're interested below is the complete list of numbers for Seed 13:


64, 63, 98, 48, 62, 36, 50, 23, 20, 59,
46, 5, 91, 85, 81, 96, 38, 66, 27, 29,
66, 68, 27, 86, 61, 9, 50, 67, 64, 15,
83, 70, 26, 47, 10, 68, 38, 26, 97, 8,
24, 68, 1, 18, 88, 28, 77, 95, 57, 99,
6, 26, 56, 23, 81, 98, 21, 47, 9, 16,
90, 95, 76, 58, 93, 76, 99, 43, 74, 69,
66, 51, 42, 66, 10, 78, 12, 4, 2, 31,
52, 83, 18, 18, 73, 87, 84, 65, 75, 60,
15, 17, 38, 45, 14, 7, 85, 67, 27, 84,
62, 67, 11, 83, 52, 72, 36, 7, 50, 90,
8, 15, 67, 89, 86, 43, 22, 78, 72, 44,
43, 28, 22, 97, 21, 32, 47, 88, 25, 10,
88, 80, 70, 2, 92, 29, 41, 25, 4, 79,
44, 11, 6, 64, 83, 94, 40, 54, 56, 12,
13, 18, 55, 6, 49, 48, 98, 61, 49, 55,
72, 16, 85, 96, 14, 30, 58, 55, 42, 28,
7, 5, 70, 14, 87, 63, 80, 40, 32, 34,
3, 64, 95, 1, 0, 89, 81, 73, 89, 34,
75, 13, 94, 71, 12, 37, 66, 35, 37, 94,
78, 38, 91, 58, 89, 41, 46, 44, 14, 44,
19, 77, 79, 26, 77, 74, 49, 61, 82, 55,
74, 0, 30, 78, 49, 27, 4, 19, 1, 93,
35, 13, 21, 8, 43, 62, 94, 73, 57, 84,
32, 92, 11, 25, 3, 24, 96, 65, 84, 65,
96, 29, 11, 45, 15, 60, 21, 2, 39, 97,
33, 53, 3, 31, 98, 29, 84, 96, 20, 82,
99, 57, 79, 3, 59, 69, 25, 54, 77, 52,
92, 56, 41, 81, 37, 92, 71, 17, 5, 51,
60, 54, 89, 76, 17, 37, 91, 30, 46, 3,
32, 61, 38, 82, 69, 46, 72, 70, 12, 22,
63, 93, 76, 58, 52, 75, 5, 56, 10, 26,
39, 65, 53, 68, 45, 97, 1, 48, 33, 20,
1, 47, 24, 55, 40, 31, 51, 59, 91, 85,
72, 23, 99, 35, 6, 99, 97, 79, 7, 76,
57, 10, 35, 48, 71, 31, 34, 9, 39, 30,
15, 51, 93, 73, 40, 67, 91, 93, 85, 98,
36, 45, 11, 13, 2, 78, 25, 13, 59, 50,
2, 80, 28, 90, 17, 16, 36, 7, 32, 60,
46, 92, 42, 41, 16, 82, 8, 86, 18, 47,
90, 80, 45, 22, 20, 60, 88, 61, 54, 29,
54, 90, 4, 40, 30, 5, 19, 71, 42, 87,
64, 69, 37, 74, 94, 48, 51, 21, 22, 19,
59, 56, 79, 77, 74, 65, 87, 23, 63, 69,
33, 0, 49, 63, 53, 24, 17, 39, 9, 83,
86, 12, 24, 86, 87, 20, 31, 62, 14, 6,
23, 58, 28, 0, 4, 57, 81, 52, 53, 73,
44, 19, 95, 34, 34, 39, 88, 80, 71, 27,
62, 50, 42, 33, 68, 53, 35, 41, 75, 8,
0, 95, 75, 16, 82, 70, 36, 43, 9, 33