{"action":"created","comment":{"url":"https://api.github.com/repos/EasyRPG/Player/pulls/comments/230555519","pull_request_review_id":171328030,"id":230555519,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMDU1NTUxOQ==","diff_hunk":"@@ -918,25 +935,61 @@ void Game_Map::UpdateEncounterSteps() {\n \t\treturn;\n \t}\n \n-\tlocation.encounter_steps = location.encounter_steps - terrain->encounter_rate;\n+\tlocation.encounter_steps += terrain->encounter_rate;\n \n-\tif (location.encounter_steps <= 0) {\n-\t\tResetEncounterSteps();\n-\t\tPrepareEncounter();\n+\tstruct Row {\n+\t\tint ratio;\n+\t\tfloat pmod;\n+\t};\n+\n+#if 1\n+\tstatic constexpr Row enc_table[] = {\n+\t\t{ 0, 0.0625},\n+\t\t{ 20, 0.125 },\n+\t\t{ 40, 0.25 },\n+\t\t{ 60, 0.5 },\n+\t\t{ 100, 2.0 },\n+\t\t{ 140, 4.0 },\n+\t\t{ 160, 8.0 },\n+\t\t{ 180, 16.0 },\n+\t\t{ INT_MAX, 16.0 }\n+\t};\n+#else\n+\t//Old versions of RM2k used this table.\n+\t//Left here for posterity.\n+\tstatic constexpr Row enc_table[] = {\n+\t\t{ 0, 0.5 },\n+\t\t{ 20, 2.0 / 3.0 },\n+\t\t{ 50, 5.0 / 6.0 },\n+\t\t{ 100, 6.0 / 5.0 },\n+\t\t{ 200, 3.0 / 2.0 },\n+\t\t{ INT_MAX, 3.0 / 2.0 }\n+\t};\n+#endif\n+\tconst auto encounter_rate = GetEncounterRate();\n+\tconst auto ratio = location.encounter_steps / encounter_rate;\n+\n+\tauto& idx = last_encounter_idx;\n+\twhile (ratio > enc_table[idx+1].ratio) {\n+\t\t++idx;\n \t}\n-}\n+\tconst auto& row = enc_table[idx];\n \n-void Game_Map::ResetEncounterSteps() {\n-\tint rate = GetEncounterRate();\n-\tif (rate > 0) {\n-\t\tint throw_one = Utils::GetRandomNumber(0, rate - 1);\n-\t\tint throw_two = Utils::GetRandomNumber(0, rate - 1);\n+\tconst auto pmod = row.pmod;\n+\tconst auto p = (1.0f / float(encounter_rate)) * pmod * (float(terrain->encounter_rate) / 100.0f);\n+\tauto draw = std::uniform_real_distribution<float>()(Utils::GetRNG());","path":"src/game_map.cpp","position":119,"original_position":119,"commit_id":"7784662ed413049d0f741d734334d78b2261ec3a","original_commit_id":"7784662ed413049d0f741d734334d78b2261ec3a","user":{"login":"fmatthew5876","id":1198466,"node_id":"MDQ6VXNlcjExOTg0NjY=","avatar_url":"https://avatars1.githubusercontent.com/u/1198466?v=4","gravatar_id":"","url":"https://api.github.com/users/fmatthew5876","html_url":"https://github.com/fmatthew5876","followers_url":"https://api.github.com/users/fmatthew5876/followers","following_url":"https://api.github.com/users/fmatthew5876/following{/other_user}","gists_url":"https://api.github.com/users/fmatthew5876/gists{/gist_id}","starred_url":"https://api.github.com/users/fmatthew5876/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmatthew5876/subscriptions","organizations_url":"https://api.github.com/users/fmatthew5876/orgs","repos_url":"https://api.github.com/users/fmatthew5876/repos","events_url":"https://api.github.com/users/fmatthew5876/events{/privacy}","received_events_url":"https://api.github.com/users/fmatthew5876/received_events","type":"User","site_admin":false},"body":"Good question. I can't find anything that guarantees this. \r\n\r\n`uniform_real_distribution` does not actually play a part in drawing random numbers. The rng stored in `Utils::GetRNG()` does that. The distribution is just a deterministic mathematical function which takes an input random number in some integer range and converts it to floating point. I guess standard library implementations could use different combinations of floating point expressions which could result is slightly different answers.\r\n\r\nThat being said, this is the right way to do this. Modulus and all the other tricks we used in the past with C `rand()` are bad. They don't actually give you good random numbers.\r\n\r\nhttps://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution","created_at":"2018-11-03T13:43:56Z","updated_at":"2018-11-03T13:43:56Z","html_url":"https://github.com/EasyRPG/Player/pull/1455#discussion_r230555519","pull_request_url":"https://api.github.com/repos/EasyRPG/Player/pulls/1455","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/comments/230555519"},"html":{"href":"https://github.com/EasyRPG/Player/pull/1455#discussion_r230555519"},"pull_request":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/1455"}},"in_reply_to_id":230555187},"pull_request":{"url":"https://api.github.com/repos/EasyRPG/Player/pulls/1455","id":223430112,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIzNDMwMTEy","html_url":"https://github.com/EasyRPG/Player/pull/1455","diff_url":"https://github.com/EasyRPG/Player/pull/1455.diff","patch_url":"https://github.com/EasyRPG/Player/pull/1455.patch","issue_url":"https://api.github.com/repos/EasyRPG/Player/issues/1455","number":1455,"state":"open","locked":false,"title":"Random Encounters fixes","user":{"login":"fmatthew5876","id":1198466,"node_id":"MDQ6VXNlcjExOTg0NjY=","avatar_url":"https://avatars1.githubusercontent.com/u/1198466?v=4","gravatar_id":"","url":"https://api.github.com/users/fmatthew5876","html_url":"https://github.com/fmatthew5876","followers_url":"https://api.github.com/users/fmatthew5876/followers","following_url":"https://api.github.com/users/fmatthew5876/following{/other_user}","gists_url":"https://api.github.com/users/fmatthew5876/gists{/gist_id}","starred_url":"https://api.github.com/users/fmatthew5876/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmatthew5876/subscriptions","organizations_url":"https://api.github.com/users/fmatthew5876/orgs","repos_url":"https://api.github.com/users/fmatthew5876/repos","events_url":"https://api.github.com/users/fmatthew5876/events{/privacy}","received_events_url":"https://api.github.com/users/fmatthew5876/received_events","type":"User","site_admin":false},"body":"Depends on:  #1441\r\n\r\nInfo from here: https://github.com/EasyRPG/liblcf/issues/261\r\n\r\n* Correctly load encounter_rate from saved game\r\n* Compute first strike chance on random encounter.","created_at":"2018-10-16T23:52:37Z","updated_at":"2018-11-03T13:43:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b4812bc05f93919c9819aa9fd8f8b29199bbcd40","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":33490895,"node_id":"MDU6TGFiZWwzMzQ5MDg5NQ==","url":"https://api.github.com/repos/EasyRPG/Player/labels/Battle","name":"Battle","color":"C0C0FF","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/EasyRPG/Player/pulls/1455/commits","review_comments_url":"https://api.github.com/repos/EasyRPG/Player/pulls/1455/comments","review_comment_url":"https://api.github.com/repos/EasyRPG/Player/pulls/comments{/number}","comments_url":"https://api.github.com/repos/EasyRPG/Player/issues/1455/comments","statuses_url":"https://api.github.com/repos/EasyRPG/Player/statuses/7784662ed413049d0f741d734334d78b2261ec3a","head":{"label":"fmatthew5876:save_steps","ref":"save_steps","sha":"7784662ed413049d0f741d734334d78b2261ec3a","user":{"login":"fmatthew5876","id":1198466,"node_id":"MDQ6VXNlcjExOTg0NjY=","avatar_url":"https://avatars1.githubusercontent.com/u/1198466?v=4","gravatar_id":"","url":"https://api.github.com/users/fmatthew5876","html_url":"https://github.com/fmatthew5876","followers_url":"https://api.github.com/users/fmatthew5876/followers","following_url":"https://api.github.com/users/fmatthew5876/following{/other_user}","gists_url":"https://api.github.com/users/fmatthew5876/gists{/gist_id}","starred_url":"https://api.github.com/users/fmatthew5876/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmatthew5876/subscriptions","organizations_url":"https://api.github.com/users/fmatthew5876/orgs","repos_url":"https://api.github.com/users/fmatthew5876/repos","events_url":"https://api.github.com/users/fmatthew5876/events{/privacy}","received_events_url":"https://api.github.com/users/fmatthew5876/received_events","type":"User","site_admin":false},"repo":{"id":149674899,"node_id":"MDEwOlJlcG9zaXRvcnkxNDk2NzQ4OTk=","name":"Player","full_name":"fmatthew5876/Player","private":false,"owner":{"login":"fmatthew5876","id":1198466,"node_id":"MDQ6VXNlcjExOTg0NjY=","avatar_url":"https://avatars1.githubusercontent.com/u/1198466?v=4","gravatar_id":"","url":"https://api.github.com/users/fmatthew5876","html_url":"https://github.com/fmatthew5876","followers_url":"https://api.github.com/users/fmatthew5876/followers","following_url":"https://api.github.com/users/fmatthew5876/following{/other_user}","gists_url":"https://api.github.com/users/fmatthew5876/gists{/gist_id}","starred_url":"https://api.github.com/users/fmatthew5876/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmatthew5876/subscriptions","organizations_url":"https://api.github.com/users/fmatthew5876/orgs","repos_url":"https://api.github.com/users/fmatthew5876/repos","events_url":"https://api.github.com/users/fmatthew5876/events{/privacy}","received_events_url":"https://api.github.com/users/fmatthew5876/received_events","type":"User","site_admin":false},"html_url":"https://github.com/fmatthew5876/Player","description":"RPG Maker 2000/2003 and EasyRPG games interpreter","fork":true,"url":"https://api.github.com/repos/fmatthew5876/Player","forks_url":"https://api.github.com/repos/fmatthew5876/Player/forks","keys_url":"https://api.github.com/repos/fmatthew5876/Player/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fmatthew5876/Player/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fmatthew5876/Player/teams","hooks_url":"https://api.github.com/repos/fmatthew5876/Player/hooks","issue_events_url":"https://api.github.com/repos/fmatthew5876/Player/issues/events{/number}","events_url":"https://api.github.com/repos/fmatthew5876/Player/events","assignees_url":"https://api.github.com/repos/fmatthew5876/Player/assignees{/user}","branches_url":"https://api.github.com/repos/fmatthew5876/Player/branches{/branch}","tags_url":"https://api.github.com/repos/fmatthew5876/Player/tags","blobs_url":"https://api.github.com/repos/fmatthew5876/Player/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fmatthew5876/Player/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fmatthew5876/Player/git/refs{/sha}","trees_url":"https://api.github.com/repos/fmatthew5876/Player/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fmatthew5876/Player/statuses/{sha}","languages_url":"https://api.github.com/repos/fmatthew5876/Player/languages","stargazers_url":"https://api.github.com/repos/fmatthew5876/Player/stargazers","contributors_url":"https://api.github.com/repos/fmatthew5876/Player/contributors","subscribers_url":"https://api.github.com/repos/fmatthew5876/Player/subscribers","subscription_url":"https://api.github.com/repos/fmatthew5876/Player/subscription","commits_url":"https://api.github.com/repos/fmatthew5876/Player/commits{/sha}","git_commits_url":"https://api.github.com/repos/fmatthew5876/Player/git/commits{/sha}","comments_url":"https://api.github.com/repos/fmatthew5876/Player/comments{/number}","issue_comment_url":"https://api.github.com/repos/fmatthew5876/Player/issues/comments{/number}","contents_url":"https://api.github.com/repos/fmatthew5876/Player/contents/{+path}","compare_url":"https://api.github.com/repos/fmatthew5876/Player/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fmatthew5876/Player/merges","archive_url":"https://api.github.com/repos/fmatthew5876/Player/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fmatthew5876/Player/downloads","issues_url":"https://api.github.com/repos/fmatthew5876/Player/issues{/number}","pulls_url":"https://api.github.com/repos/fmatthew5876/Player/pulls{/number}","milestones_url":"https://api.github.com/repos/fmatthew5876/Player/milestones{/number}","notifications_url":"https://api.github.com/repos/fmatthew5876/Player/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fmatthew5876/Player/labels{/name}","releases_url":"https://api.github.com/repos/fmatthew5876/Player/releases{/id}","deployments_url":"https://api.github.com/repos/fmatthew5876/Player/deployments","created_at":"2018-09-20T21:52:44Z","updated_at":"2018-11-01T21:41:46Z","pushed_at":"2018-11-03T12:28:26Z","git_url":"git://github.com/fmatthew5876/Player.git","ssh_url":"git@github.com:fmatthew5876/Player.git","clone_url":"https://github.com/fmatthew5876/Player.git","svn_url":"https://github.com/fmatthew5876/Player","homepage":"https://easyrpg.org/player/","size":30377,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"EasyRPG:master","ref":"master","sha":"3fa354c9715c036093f3b344d73fcfa28c9d9095","user":{"login":"EasyRPG","id":1331871,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzE4NzE=","avatar_url":"https://avatars0.githubusercontent.com/u/1331871?v=4","gravatar_id":"","url":"https://api.github.com/users/EasyRPG","html_url":"https://github.com/EasyRPG","followers_url":"https://api.github.com/users/EasyRPG/followers","following_url":"https://api.github.com/users/EasyRPG/following{/other_user}","gists_url":"https://api.github.com/users/EasyRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/EasyRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EasyRPG/subscriptions","organizations_url":"https://api.github.com/users/EasyRPG/orgs","repos_url":"https://api.github.com/users/EasyRPG/repos","events_url":"https://api.github.com/users/EasyRPG/events{/privacy}","received_events_url":"https://api.github.com/users/EasyRPG/received_events","type":"Organization","site_admin":false},"repo":{"id":3297519,"node_id":"MDEwOlJlcG9zaXRvcnkzMjk3NTE5","name":"Player","full_name":"EasyRPG/Player","private":false,"owner":{"login":"EasyRPG","id":1331871,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzMzE4NzE=","avatar_url":"https://avatars0.githubusercontent.com/u/1331871?v=4","gravatar_id":"","url":"https://api.github.com/users/EasyRPG","html_url":"https://github.com/EasyRPG","followers_url":"https://api.github.com/users/EasyRPG/followers","following_url":"https://api.github.com/users/EasyRPG/following{/other_user}","gists_url":"https://api.github.com/users/EasyRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/EasyRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EasyRPG/subscriptions","organizations_url":"https://api.github.com/users/EasyRPG/orgs","repos_url":"https://api.github.com/users/EasyRPG/repos","events_url":"https://api.github.com/users/EasyRPG/events{/privacy}","received_events_url":"https://api.github.com/users/EasyRPG/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/EasyRPG/Player","description":"RPG Maker 2000/2003 and EasyRPG games interpreter","fork":false,"url":"https://api.github.com/repos/EasyRPG/Player","forks_url":"https://api.github.com/repos/EasyRPG/Player/forks","keys_url":"https://api.github.com/repos/EasyRPG/Player/keys{/key_id}","collaborators_url":"https://api.github.com/repos/EasyRPG/Player/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/EasyRPG/Player/teams","hooks_url":"https://api.github.com/repos/EasyRPG/Player/hooks","issue_events_url":"https://api.github.com/repos/EasyRPG/Player/issues/events{/number}","events_url":"https://api.github.com/repos/EasyRPG/Player/events","assignees_url":"https://api.github.com/repos/EasyRPG/Player/assignees{/user}","branches_url":"https://api.github.com/repos/EasyRPG/Player/branches{/branch}","tags_url":"https://api.github.com/repos/EasyRPG/Player/tags","blobs_url":"https://api.github.com/repos/EasyRPG/Player/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/EasyRPG/Player/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/EasyRPG/Player/git/refs{/sha}","trees_url":"https://api.github.com/repos/EasyRPG/Player/git/trees{/sha}","statuses_url":"https://api.github.com/repos/EasyRPG/Player/statuses/{sha}","languages_url":"https://api.github.com/repos/EasyRPG/Player/languages","stargazers_url":"https://api.github.com/repos/EasyRPG/Player/stargazers","contributors_url":"https://api.github.com/repos/EasyRPG/Player/contributors","subscribers_url":"https://api.github.com/repos/EasyRPG/Player/subscribers","subscription_url":"https://api.github.com/repos/EasyRPG/Player/subscription","commits_url":"https://api.github.com/repos/EasyRPG/Player/commits{/sha}","git_commits_url":"https://api.github.com/repos/EasyRPG/Player/git/commits{/sha}","comments_url":"https://api.github.com/repos/EasyRPG/Player/comments{/number}","issue_comment_url":"https://api.github.com/repos/EasyRPG/Player/issues/comments{/number}","contents_url":"https://api.github.com/repos/EasyRPG/Player/contents/{+path}","compare_url":"https://api.github.com/repos/EasyRPG/Player/compare/{base}...{head}","merges_url":"https://api.github.com/repos/EasyRPG/Player/merges","archive_url":"https://api.github.com/repos/EasyRPG/Player/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/EasyRPG/Player/downloads","issues_url":"https://api.github.com/repos/EasyRPG/Player/issues{/number}","pulls_url":"https://api.github.com/repos/EasyRPG/Player/pulls{/number}","milestones_url":"https://api.github.com/repos/EasyRPG/Player/milestones{/number}","notifications_url":"https://api.github.com/repos/EasyRPG/Player/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/EasyRPG/Player/labels{/name}","releases_url":"https://api.github.com/repos/EasyRPG/Player/releases{/id}","deployments_url":"https://api.github.com/repos/EasyRPG/Player/deployments","created_at":"2012-01-29T14:35:47Z","updated_at":"2018-11-03T13:26:40Z","pushed_at":"2018-11-03T13:26:37Z","git_url":"git://github.com/EasyRPG/Player.git","ssh_url":"git@github.com:EasyRPG/Player.git","clone_url":"https://github.com/EasyRPG/Player.git","svn_url":"https://github.com/EasyRPG/Player","homepage":"https://easyrpg.org/player/","size":30018,"stargazers_count":341,"watchers_count":341,"language":"C++","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":78,"mirror_url":null,"archived":false,"open_issues_count":190,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":78,"open_issues":190,"watchers":341,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/1455"},"html":{"href":"https://github.com/EasyRPG/Player/pull/1455"},"issue":{"href":"https://api.github.com/repos/EasyRPG/Player/issues/1455"},"comments":{"href":"https://api.github.com/repos/EasyRPG/Player/issues/1455/comments"},"review_comments":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/1455/comments"},"review_comment":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/EasyRPG/Player/pulls/1455/commits"},"statuses":{"href":"https://api.github.com/repos/EasyRPG/Player/statuses/7784662ed413049d0f741d734334d78b2261ec3a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"fmatthew5876"}}