Skip to content

Instantly share code, notes, and snippets.

@Osinko
Last active August 15, 2019 11:12
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/1fbd5942cece26db456322fa4c2c0581 to your computer and use it in GitHub Desktop.
Save Osinko/1fbd5942cece26db456322fa4c2c0581 to your computer and use it in GitHub Desktop.
ポアソン分布と二項分布の関係の検証
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Case4 : MonoBehaviour
{
//ある交差点で1ヵ月に発生する交通事故の死亡者数は平均1.5人だった。今後、1ヵ月に死亡事故が発生数する確率は?
void Start()
{
for (int j = 0; j < 10000; j++)
{
float winCount = 0;
for (int i = 0; i < 30; i++) //30日のシミュレーション
{
if (TossDice()) winCount++;
}
print(winCount);
}
}
public bool TossDice()
{
if (Random.Range(1, 100 + 1) <= 5) return true; // 1.5/30=0.05。1日間で0.05人のベルヌーイ試行と計算
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment