Created
July 30, 2019 07:23
-
-
Save Osinko/538604befc24ecce95a99a2944276c89 to your computer and use it in GitHub Desktop.
サイコロのテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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