Skip to content

Instantly share code, notes, and snippets.

@Osinko
Created July 30, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Osinko/ab35289bc87cae82a17446e4b54db45d to your computer and use it in GitHub Desktop.
Save Osinko/ab35289bc87cae82a17446e4b54db45d to your computer and use it in GitHub Desktop.
二項分布のテスト
using UnityEngine;
public class Dice : MonoBehaviour
{
void Start()
{
Sampling(6, 60, 5, 100000);
Sampling(6, 60, 10, 100000);
Sampling(6, 60, 16, 100000);
}
private void Sampling(int dice, int n, int hit, int sampling)
{
int total = 0;
for (int j = 0; j < sampling; j++)
{
int winCont = 0;
for (int i = 0; i < n; i++)
{
if (TossDice(dice) == 1) winCont++;
}
if (winCont >= hit) total++;
}
print((float)total / (float)sampling);
}
public int TossDice(int dice)
{
return Random.Range(1, dice + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment