Exponential distribution to represent crash game

367 Views Asked by At

I'm sure many of you have heard of the game called crash. Some popular examples of this are satoshi, bustabit.

It's pretty complicated to explain, so I will begin assuming that you are familiar with it.

Anyways, my goal is to recreate something along these lines. I want to make a function that will give me an exponential distribution double PRNG between 1 and 100.

Basically, a random double between 1 and 100 in which the probability of getting a double near 1 is much more likely than getting a double closer to 100.

I've been experimenting with a few things so far, but I really just can't figure this one out. Any insight as to how this could be achieved would be greatly appreciated.

1

There are 1 best solutions below

0
On

You can achieve this using a bias function.

public static void main(final String[] args) {
    double sum = 0;
    for (int i = 0; i < 100; i++) {
        final double x = Math.random();
        sum += biasFunction(x, 0.7);
    }
    System.out.println(sum);
}

public static double biasFunction(final double x, final double bias) {
    // Adjust input to make control feel more linear
    final double f = Math.pow(1 - bias, 3);
    return (x * f) / (x * f - x + 1);
}

The more you increase the bias, the more your result will go against zero. You could also just multiply the result of the function by 100 instead of taking an average.

Take a look at this visualization.