# -*- coding: utf-8 -*- import random class Dice(object): def throw(self): return random.randint(1, 6) # -*- coding: utf-8 -*- import collections import unittest import dice from scipy import stats class TestDice(unittest.TestCase): def setUp(self): self.__target = dice.Dice() def test_throw(self): # 6000回実行する result = [self.__target.throw() for n in range(0, 6000)] # 実行結果の集計 counted = collections
![Pythonでランダムな値を返すメソッドのテスト - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/6a0405b189c23fbaffd57aff08472b48c6dc134b/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Fadvent-calendar-ogp-background-7940cd1c8db80a7ec40711d90f43539e.jpg%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9UHl0aG9uJUUzJTgxJUE3JUUzJTgzJUE5JUUzJTgzJUIzJUUzJTgzJTgwJUUzJTgzJUEwJUUzJTgxJUFBJUU1JTgwJUE0JUUzJTgyJTkyJUU4JUJGJTk0JUUzJTgxJTk5JUUzJTgzJUExJUUzJTgyJUJEJUUzJTgzJTgzJUUzJTgzJTg5JUUzJTgxJUFFJUUzJTgzJTg2JUUzJTgyJUI5JUUzJTgzJTg4JnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnR4dC1jb2xvcj0lMjMzQTNDM0MmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmcz1jMDEwNDcwMWNlM2UwOTc0YzM4NDc2NDg1MzRlODc2YQ%26mark-x%3D120%26mark-y%3D96%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9OTcyJnR4dD0lNDBtaWFfMDAzMiZ0eHQtY29sb3I9JTIzM0EzQzNDJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9MGM2OWQwMjhkMmUzNDc3MzMwZjFhZWFkMDUxYmI5MDk%26blend-x%3D120%26blend-y%3D500%26blend-mode%3Dnormal%26s%3Dffb169b785eb523211765a21b5997ffe)