Horje
weighted random c# Code Example
weighted random c#

public static readonly int RATIO_CHANCE_A = 10;
public static readonly int RATIO_CHANCE_B = 30;
//                         ...
public static readonly int RATIO_CHANCE_N = 60;

public static readonly int RATIO_TOTAL = RATIO_CHANCE_A
                                       + RATIO_CHANCE_B
                                         // ...
                                       + RATIO_CHANCE_N;

Random random = new Random();
int x = random.Next(0, RATIO_TOTAL);

if ((x -= RATIO_CHANCE_A) < 0) // Test for A
{ 
     do_something1();
} 
else if ((x -= RATIO_CHANCE_B) < 0) // Test for B
{ 
     do_something2();
}
// ... etc
else // No need for final if statement
{ 
     do_somethingN();
}





Csharp

Related
Reporting Progress from Async Tasks c# Code Example Reporting Progress from Async Tasks c# Code Example
unity camera movement script Code Example unity camera movement script Code Example
bubble sort recursive c# Code Example bubble sort recursive c# Code Example
how to full screen login form using C# MVC Code Example how to full screen login form using C# MVC Code Example
Go Statement in CSharp Code Example Go Statement in CSharp Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9