Skip to content

Instantly share code, notes, and snippets.

@Osinko
Created July 30, 2019 07:23
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/538604befc24ecce95a99a2944276c89 to your computer and use it in GitHub Desktop.
Save Osinko/538604befc24ecce95a99a2944276c89 to your computer and use it in GitHub Desktop.
サイコロのテスト
using UnityEngine;
public class Dice : MonoBehaviour
{
void Start()
{
Sampling(60, 60, 100000);
Sampling(600, 600, 100000);
Sampling(6000, 6000, 100000);
}
private void Sampling(int dice, int n, 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 > 0) total++;
}
print(1-((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