{"action":"closed","issue":{"url":"https://api.github.com/repos/8INF840-uqac/Devoir1/issues/9","repository_url":"https://api.github.com/repos/8INF840-uqac/Devoir1","labels_url":"https://api.github.com/repos/8INF840-uqac/Devoir1/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/8INF840-uqac/Devoir1/issues/9/comments","events_url":"https://api.github.com/repos/8INF840-uqac/Devoir1/issues/9/events","html_url":"https://github.com/8INF840-uqac/Devoir1/issues/9","id":229869345,"number":9,"title":"Random number generation is not uniform","user":{"login":"Elried","id":5961692,"avatar_url":"https://avatars2.githubusercontent.com/u/5961692?v=3","gravatar_id":"","url":"https://api.github.com/users/Elried","html_url":"https://github.com/Elried","followers_url":"https://api.github.com/users/Elried/followers","following_url":"https://api.github.com/users/Elried/following{/other_user}","gists_url":"https://api.github.com/users/Elried/gists{/gist_id}","starred_url":"https://api.github.com/users/Elried/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Elried/subscriptions","organizations_url":"https://api.github.com/users/Elried/orgs","repos_url":"https://api.github.com/users/Elried/repos","events_url":"https://api.github.com/users/Elried/events{/privacy}","received_events_url":"https://api.github.com/users/Elried/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-19T04:39:12Z","updated_at":"2017-05-19T05:20:56Z","closed_at":"2017-05-19T05:20:56Z","body":"```cpp\r\nstd::random_device Card::rd;\r\nstd::mt19937 Card::mt(Card::rd());\r\nstd::uniform_int_distribution<unsigned short> Card::dist(0, Card::MAXRAND);\r\n\r\nCard::Card() {\r\n    m_score = dist(Card::mt) % MAXSCORE + 1;\r\n    m_bonus = dist(Card::mt) % MAXBONUS + 1;\r\n    m_color = static_cast<Color>(dist(Card::mt) % 2);\r\n}\r\n```\r\nThis way of generating number implies that the generation of m_bonus is not uniform (less chances to get a 4 than to get a 1, a 2 or a 3\r\n\r\nIn the same fashion, nothing guaranties the uniform distribution of m_score\r\nSomething like that should do the trick :\r\n```cpp\r\nstd::random_device Card::rd;\r\nstd::mt19937 Card::mt(Card::rd());\r\n\r\nCard::Card() {\r\n    static std::uniform_int_distribution<unsigned short> Card::dist_score(1, Card::MAXSCORE);\r\n    static std::uniform_int_distribution<unsigned short> Card::dist_bonus(1, Card::MAXBONUS);\r\n    static std::uniform_int_distribution<unsigned short> Card::dist_color(1, Card::MAXCOLOR);\r\n\r\n    m_score = dist_score(Card::mt);\r\n    m_bonus = dist_bonus(Card::mt);\r\n    m_color = static_cast<Color>(dist_color(Card::mt));\r\n}\r\n```\r\nMoreover this allows more flexibility when selecting which probability law should be used on which element. it also allows to change the upper limits while guarantying the uniform distribution of values"}}
{"actor":{"display_login":"AmarOk1412"}}