How do you guys make random more random?

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
As we all know, true random has yet to be achieve in computer science. The existing way to get a random value aren't exactly and and all follow an algorithm. I've been using Math.random() to get a random value in my plugins, but sometimes when play testing I just notice it is a really imperfect solution. So what do you guys do to make random more random?
 

lianderson

Veteran
Veteran
Joined
Dec 27, 2012
Messages
442
Reaction score
340
First Language
English
Primarily Uses
N/A
Make it roll at random time frames and have it do this a random amount of times. That would surely make your random rolls more random.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,634
Reaction score
5,114
First Language
English
Primarily Uses
RMVXA
In my own game (for Ace rather than MV) I randomize the setup to a lot of mini-games, and I haven't found any kind of patterns or consistencies developing that suggest the "pseudo-random" numbers that computers generate is inadequate for use in my game. So I guess the short answer is "I don't". And in the same breath, I'd be really curious where you have seen this lack of randomness actually show up in your playtests. But if I had to achieve true(r) randomness, there are a few things I might try:
  • An even greater level of randomization could probably be achieved by storing a random float very early in the game - after it starts but before I need a random number for any other purpose - and then whenever I take a random number (like Math.random() in a larger method), I'd run it through a special method that would add or subtract each important digit of the stored float from each digit in the new random number, to create an even more random number that I'd actually use for whatever purpose. For example, if the stored number was 0.350909780... and the new number chosen was 0.235741536... the result would be 0.585640216... This is the two floats added together, BUT numbers are never carried (for example the 9 + 7 becomes 6, not 16), so each digit is independent and "random". I'd use this final number (the 0.5856...) to make any comparisons I needed in the game's processing, like a check whether a random is between 0.5 and 0.6. I would probably change the stored float up every once in a while as well.
  • If there was a REALLY pressing need for a truly random number, such as an in-game lottery in a massively multiplayer project I made, I would probably try to run a call to random.org which combines a computer's RNG with atmospheric noise to achieve true randomness.
  • Some engines do allow you to randomize the seed the RNG works from (or to set it manually if you do want consistent behavior in playtesting). GameMaker Studio, for instance, has a randomise() function that sets the seed randomly, making your subsequent RNG draws much less consistent. I don't think that RPG Maker offers this, though.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Maybe you can write something that sends a request to random.org? From what they write that would be a truly random value.
It's impossible to have a generic random algorithm, because it is an algorithm and as such is programmed in some way. If you want to add on randomness, you can have an unpredictable seed that changes every second. However, in order to have an unpredictable seed you'd need to implement real world events you have no control of.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
@Poryg Unfortunately I would prefer my game to be able to run without internet the same way it does with internet. I know it is impossible to generate truly random numbers, but I think there are better ways than the default Math.random() in javascript.

@Wavelength I guess my question would have been "can I seed a value before using a random number generator", but apparently we can't with Math.random().

@lianderson I can't really dissociate the random and the frames. A skill takes x amount of frames to execute and always generate damage after the same amount of frames.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,418
Reaction score
7,709
First Language
German
Primarily Uses
RMMV
The existing algorithms do a relatively good job of simulating randomness. I haven't tested this specific case, but they had to do a really terrible job to make the random generator go wrong, unless it is one of two very specific cases that are in your implementation rather than in the original algorithm.

1) too low or too high probabilities
random generators are geared toward the middle, their errors are with the extreme border values.
You can detect this by making hundreds of tests against <0.5% and >99.5% - you won't find much errors when checking 50%-options.

However any game that really uses such extreme probabilities is broken in my opinion - just check the internet on what gamers had to say about grinding for a weapon required to win that had a loot rate of 0.1%. Has been done before, and the ****storm wasn't nice.
Same goes with 99.5% to hit - simply say it always hits instead of creating lag by high percantage checks.

2) recursive randomness
Some people try to improve the existing random generators by manipulating the results through additional formula.
Unfortunately that is often a bad idea, because you need to know exactly what you do to really improve randomness. A lot of people that only guessed how it should be done instead implemented a recursive loop that destroyed randomness.
So if you do something more complex than a random counter or check and find an unexpected probability there, then you should doublecheck your own mathematics and coding before assuming that the random function itself went wrong.
 

lianderson

Veteran
Veteran
Joined
Dec 27, 2012
Messages
442
Reaction score
340
First Language
English
Primarily Uses
N/A
What exactly are you trying to get done in your game? Because, making random more random is pretty vague. If you tell us what you're needing it for, we might be able to help you out in more detail.
 
Last edited:

TWings

The Dragon Whisperer
Veteran
Joined
Jul 26, 2017
Messages
527
Reaction score
860
First Language
French
Primarily Uses
RMMV
"True randomness" is actually very flawed and not that much appreciated from a human beeing point of view. Because what your average people expect from randomness is actually not what randomness is or does !
Usually when you say "random", people will pretty much expect a different result at every draw. But really you can draw a '5' three times in a row with it beeing completely random (not matter how small the odds are). The problem is that's the kind of result that people tend to perceive as not random.
A simple thing you can do to try to please people, is actually to remember the previous draw and remove it from the possibilities of the next draw. In some cases, weighted randomness can be welcomed too. It's actually not completely random anymore, but really, people don't get along well with true randomness.
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
I've been using Math.random() to get a random value in my plugins, but sometimes when play testing I just notice it is a really imperfect solution.
Curious, do you have examples here?
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
@Aloe Guvner With only around 1.5-2.5% chance to miss a regular attack (without any state), I sometimes miss 3-5 times in a row. This rarely happens, but it happened at least 7-8 times in about 100 battles. The thing is that the miss occurrences are also way too close one to another, even if it's not always one after another. Example: 4 misses in the last 7 attacks, than after that like 30-50 regular attacks without missing, than another 3 misses in 6 attacks, etc.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,418
Reaction score
7,709
First Language
German
Primarily Uses
RMMV
how is the miss chance calculated if you say "1.5% to 2.5%"?
your description really sounds like somewhere your formulae are messed up like I described in option 2 above.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
@Andar Here's the formula:

Code:
// Miss Section
    var a_luk = act.param(7);
    var e_luk = en.getParam(7);
    var miss  = false;
    var mssChance = 50 + Math.round(Math.min( Math.max(a_luk / e_luk * 200, 50), 450 ));
    var mssRd = Math.random() * 10000;
    if (this._aStates[this._curActive]['blind'] > 0) {
        mssChance = 5000;
    }
    if (mssRd < mssChance) {
        miss = true;
    }
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Like you said, the numbers generated are pseudo-random, not true random. However, the randomness is extremely high in any modern programming language, so close to random that a human really can't tell it apart.

From your formula above, there should be mathematically between 1% and 5% chance to miss (ignoring the blind state, is that why you're missing 3-5 times in a row?).

Go ahead and paste this code into your browser's dev tools (press F12 to open the console in most browsers) and let me know what your results are:
Code:
let missCountLow = 0;
let missCountHigh = 0;
const missChanceLow = 100;  // 1%
const missChanceHigh = 500; // 5%
const trials = 1000000;
for (let i = 0; i < trials ; i++) {
    const missRandom = Math.random() * 10000;
    if (missRandom < missChanceLow) missCountLow++;
    if (missRandom < missChanceHigh) missCountHigh++;
}
console.log("Actual % miss for estimated 1% chance (1 million trials): ", missCountLow / trials * 100);
console.log("Actual % miss for estimated 5% chance (1 million trials): ", missCountHigh / trials * 100);
For me, on Firefox, I got 0.98% for the first one and 5.01% for the second one. Close enough beyond the ability of a human to anecdotally tell it was imperfect.

If what you're seeing in your testing experience is contradictory to the hard numbers and the math, then either:
1. What TWings said about the perception of randomness by a human vs reality. For interesting reading, look up how Apple had to change their shuffle formula to actually be not random after people complained they got the same song twice in a row (which happens in random)
2. There's something else in the formula besides what you've shared that's influencing the results
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
We cannot say for certain that the randomness is flawed just because you missed 3-5 times in a row a few times with a 1% chance to miss.

Remember that your 1% chance to miss doesnt actually mean it will mostly be 1 miss every 100 hits, unless you're doing huge trials..

Like for example in Theo's code above, he tested for 1000 trials a few times and all of them showed results that are very close to the 2% chance he set.

Example: 4 misses in the last 7 attacks, than after that like 30-50 regular attacks without missing, than another 3 misses in 6 attacks, etc.
And that does look random, I'd actually be more wary if you miss like every 10 hits (that will look like its set to miss rather than random).

Anyway if you want it to be closer to your chances, you can try looping the random call a few times and return the last result, that will probably be more random than a single random call..
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
Numbers look fine, but the reason I've created this thread it's because the number of times the misses have been really close to each other is higher than expected. If it only happened 2-3 times only I wouldn't have started this thread.

Even though it ends up missing about 1-5% of the times, it's how close the few misses actually occur to each other. It might be a human perception of randomness, but it's still weird that 2 misses are really close to each other, than there's a huge period of time without any misses, than misses come back, and again close to each others.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
but it's still weird that 2 misses are really close to each other, than there's a huge period of time without any misses, than misses come back, and again close to each others.
Jokes on you, you can probably code that "If this actor is already missed, the next x times of attack will guarantee hit. Then send back the original rate after that", and don't ever tell the player about it so they never find it out :p
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
It might be a human perception of randomness, but it's still weird that 2 misses are really close to each other, than there's a huge period of time without any misses
Which is tbh random.. Its random because its unpredictable, if you can predict it then thats not really random at all.

Anyway, if you want to avoid successive misses, instead of relying on a full random behavior, you can always put controls to it. Like if you missed, you set a counter and the higher that counter is, you lessen the chance to miss.

It now becomes a controlled behavior though, but at least it will probably alleviate the weirdness that you're feeling.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,684
First Language
English
Primarily Uses
RMMZ
lol I like that. Control "randomness".
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Frostorm wrote on Featherbrain's profile.
Hey, so what species are your raptors? Any of these?
... so here's my main characters running around inside "Headspace", a place people use as a safe place away from anxious/panic related thinking.
Stream will be live shortly! I will be doing some music tonight! Feel free to drop by!
Made transition effects for going inside or outside using zoom, pixi filter, and a shutter effect
I have gathered enough feedback from a few selected people. But it is still available if you want to sign up https://forums.rpgmakerweb.com/index.php?threads/looking-for-testers-a-closed-tech-demo.130774/

Forum statistics

Threads
105,992
Messages
1,018,193
Members
137,772
Latest member
Kirakirna
Top