Home > Software engineering >  Get random float with % odds (Gambling Crash game style)
Get random float with % odds (Gambling Crash game style)

Time:07-16

I am trying to figure out how to create a random float with custom odds. The game i am trying to replicate is Crash. So the minimum number would be 1, and the max could be for example 1000. I have the formula from this site https://bitcointalk.org/index.php?topic=5265896.0

CRASH MULTIPLIER = [(E*100 - H)/(E-H)]/100

Also there is some .js code here from getting the number https://roobet.com/fair but it has hashes and stuff (i dont have them, and i dont need them for this project)

And found this thread too: Math behind generating random number (Crash game BTC Casino)

Anyone know how to do this in C#? Also should i be using System.Random in this? is it actually "random"?

I know how to set the odds, it would go something like this:

Random random = new Random();
double Number = random.NextDouble() * (100 - 1)   1;
if (Number == 50) //would give me 1% odds
{
   CrashRandomNumber = 1; // = means that the Crash game would crash instantly upon starting
}

CodePudding user response:

In C# try implementing it using this algorithm. It worked for me, hope it does for you

using System;
public class myClass
{
    public static void Main(string[] args)
    {
        Console.Write("Please enter a value for E :" );
        double E = Convert.ToDouble(Console.Read());
        Random rnd = new Random();
        double H = rnd.Next(1, Convert.ToInt32(E 1));
        double crash = (E*100 - H)/(100*(E-H));
        Console.WriteLine($" The value of crash is : {crash}"); 
    }
}
  • Related