{"action":"created","comment":{"url":"https://api.github.com/repos/tigera/libcalico-go/pulls/comments/77272639","id":77272639,"diff_hunk":"@@ -310,23 +311,32 @@ func randomBlockGenerator(pool cnet.IPNet) func() *cnet.IPNet {\n \tprefixLen := size - ones\n \tnumBlocks := int(math.Exp2(float64(prefixLen))) / blockSize\n \n-\t// Generate a randomly ordered slice of block indexes.\n+\t// Start at a random offset index\n \tsource := rand.NewSource(time.Now().UnixNano())\n \trandm := rand.New(source)\n-\tidxs := randm.Perm(numBlocks)\n-\ti := 0\n+\n+\t// initialIndex keeps track of the random starting point\n+\tinitialIndex := randm.Intn(numBlocks)\n+\t// i keeps track of current index while walking the blocks in a pool\n+\ti := initialIndex\n+\tnumReturned := 0\n+\n \treturn func() *cnet.IPNet {\n-\t\t// Pop a block index off of the indexes slice.\n-\t\tif len(idxs) != 0 {\n-\t\t\ti, idxs = idxs[len(idxs)-1], idxs[:len(idxs)-1]\n-\t\t} else {\n+\t\tip := incrementIP(baseIP, i*blockSize)\n+\t\tipnet := net.IPNet{ip.IP, version.BlockPrefixMask}\n+\t\ti++\n+\t\tif i >= numBlocks {","path":"lib/client/ipam_block_reader_writer.go","position":33,"original_position":33,"commit_id":"7219f329767e805c7b602c920d138ef542890cc9","original_commit_id":"7219f329767e805c7b602c920d138ef542890cc9","user":{"login":"caseydavenport","id":1944093,"avatar_url":"https://avatars.githubusercontent.com/u/1944093?v=3","gravatar_id":"","url":"https://api.github.com/users/caseydavenport","html_url":"https://github.com/caseydavenport","followers_url":"https://api.github.com/users/caseydavenport/followers","following_url":"https://api.github.com/users/caseydavenport/following{/other_user}","gists_url":"https://api.github.com/users/caseydavenport/gists{/gist_id}","starred_url":"https://api.github.com/users/caseydavenport/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseydavenport/subscriptions","organizations_url":"https://api.github.com/users/caseydavenport/orgs","repos_url":"https://api.github.com/users/caseydavenport/repos","events_url":"https://api.github.com/users/caseydavenport/events{/privacy}","received_events_url":"https://api.github.com/users/caseydavenport/received_events","type":"User","site_admin":false},"body":"I think this would be clearer like this:\r\n\r\n```go\r\nif i >= numBlocks - 1 {\r\n  // Loop back to beginning of pool rather than \r\n  // increment, because incrementing would put us outside of the pool.\r\n  i = 0\r\n} else {\r\n  // Increment to next block.\r\n  i++\r\n}\r\n```","created_at":"2016-09-01T23:33:48Z","updated_at":"2016-09-01T23:33:48Z","html_url":"https://github.com/tigera/libcalico-go/pull/119#discussion_r77272639","pull_request_url":"https://api.github.com/repos/tigera/libcalico-go/pulls/119","_links":{"self":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/comments/77272639"},"html":{"href":"https://github.com/tigera/libcalico-go/pull/119#discussion_r77272639"},"pull_request":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/119"}}},"pull_request":{"url":"https://api.github.com/repos/tigera/libcalico-go/pulls/119","id":83704895,"html_url":"https://github.com/tigera/libcalico-go/pull/119","diff_url":"https://github.com/tigera/libcalico-go/pull/119.diff","patch_url":"https://github.com/tigera/libcalico-go/pull/119.patch","issue_url":"https://api.github.com/repos/tigera/libcalico-go/issues/119","number":119,"state":"open","locked":false,"title":"random offset for IP blocks [bugfix for IPv6 blocks]","user":{"login":"gunjan5","id":5966968,"avatar_url":"https://avatars.githubusercontent.com/u/5966968?v=3","gravatar_id":"","url":"https://api.github.com/users/gunjan5","html_url":"https://github.com/gunjan5","followers_url":"https://api.github.com/users/gunjan5/followers","following_url":"https://api.github.com/users/gunjan5/following{/other_user}","gists_url":"https://api.github.com/users/gunjan5/gists{/gist_id}","starred_url":"https://api.github.com/users/gunjan5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunjan5/subscriptions","organizations_url":"https://api.github.com/users/gunjan5/orgs","repos_url":"https://api.github.com/users/gunjan5/repos","events_url":"https://api.github.com/users/gunjan5/events{/privacy}","received_events_url":"https://api.github.com/users/gunjan5/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-09-01T20:53:09Z","updated_at":"2016-09-01T23:33:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15f98a4fe481a24393ecf09fdf03a25e6acb343a","assignee":{"login":"caseydavenport","id":1944093,"avatar_url":"https://avatars.githubusercontent.com/u/1944093?v=3","gravatar_id":"","url":"https://api.github.com/users/caseydavenport","html_url":"https://github.com/caseydavenport","followers_url":"https://api.github.com/users/caseydavenport/followers","following_url":"https://api.github.com/users/caseydavenport/following{/other_user}","gists_url":"https://api.github.com/users/caseydavenport/gists{/gist_id}","starred_url":"https://api.github.com/users/caseydavenport/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseydavenport/subscriptions","organizations_url":"https://api.github.com/users/caseydavenport/orgs","repos_url":"https://api.github.com/users/caseydavenport/repos","events_url":"https://api.github.com/users/caseydavenport/events{/privacy}","received_events_url":"https://api.github.com/users/caseydavenport/received_events","type":"User","site_admin":false},"assignees":[{"login":"caseydavenport","id":1944093,"avatar_url":"https://avatars.githubusercontent.com/u/1944093?v=3","gravatar_id":"","url":"https://api.github.com/users/caseydavenport","html_url":"https://github.com/caseydavenport","followers_url":"https://api.github.com/users/caseydavenport/followers","following_url":"https://api.github.com/users/caseydavenport/following{/other_user}","gists_url":"https://api.github.com/users/caseydavenport/gists{/gist_id}","starred_url":"https://api.github.com/users/caseydavenport/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseydavenport/subscriptions","organizations_url":"https://api.github.com/users/caseydavenport/orgs","repos_url":"https://api.github.com/users/caseydavenport/repos","events_url":"https://api.github.com/users/caseydavenport/events{/privacy}","received_events_url":"https://api.github.com/users/caseydavenport/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/tigera/libcalico-go/pulls/119/commits","review_comments_url":"https://api.github.com/repos/tigera/libcalico-go/pulls/119/comments","review_comment_url":"https://api.github.com/repos/tigera/libcalico-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tigera/libcalico-go/issues/119/comments","statuses_url":"https://api.github.com/repos/tigera/libcalico-go/statuses/7219f329767e805c7b602c920d138ef542890cc9","head":{"label":"gunjan5:random-block-ipv6","ref":"random-block-ipv6","sha":"7219f329767e805c7b602c920d138ef542890cc9","user":{"login":"gunjan5","id":5966968,"avatar_url":"https://avatars.githubusercontent.com/u/5966968?v=3","gravatar_id":"","url":"https://api.github.com/users/gunjan5","html_url":"https://github.com/gunjan5","followers_url":"https://api.github.com/users/gunjan5/followers","following_url":"https://api.github.com/users/gunjan5/following{/other_user}","gists_url":"https://api.github.com/users/gunjan5/gists{/gist_id}","starred_url":"https://api.github.com/users/gunjan5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunjan5/subscriptions","organizations_url":"https://api.github.com/users/gunjan5/orgs","repos_url":"https://api.github.com/users/gunjan5/repos","events_url":"https://api.github.com/users/gunjan5/events{/privacy}","received_events_url":"https://api.github.com/users/gunjan5/received_events","type":"User","site_admin":false},"repo":{"id":67165226,"name":"libcalico-go","full_name":"gunjan5/libcalico-go","owner":{"login":"gunjan5","id":5966968,"avatar_url":"https://avatars.githubusercontent.com/u/5966968?v=3","gravatar_id":"","url":"https://api.github.com/users/gunjan5","html_url":"https://github.com/gunjan5","followers_url":"https://api.github.com/users/gunjan5/followers","following_url":"https://api.github.com/users/gunjan5/following{/other_user}","gists_url":"https://api.github.com/users/gunjan5/gists{/gist_id}","starred_url":"https://api.github.com/users/gunjan5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunjan5/subscriptions","organizations_url":"https://api.github.com/users/gunjan5/orgs","repos_url":"https://api.github.com/users/gunjan5/repos","events_url":"https://api.github.com/users/gunjan5/events{/privacy}","received_events_url":"https://api.github.com/users/gunjan5/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gunjan5/libcalico-go","description":"Golang Calico library functions:  https://www.projectcalico.org","fork":true,"url":"https://api.github.com/repos/gunjan5/libcalico-go","forks_url":"https://api.github.com/repos/gunjan5/libcalico-go/forks","keys_url":"https://api.github.com/repos/gunjan5/libcalico-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gunjan5/libcalico-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gunjan5/libcalico-go/teams","hooks_url":"https://api.github.com/repos/gunjan5/libcalico-go/hooks","issue_events_url":"https://api.github.com/repos/gunjan5/libcalico-go/issues/events{/number}","events_url":"https://api.github.com/repos/gunjan5/libcalico-go/events","assignees_url":"https://api.github.com/repos/gunjan5/libcalico-go/assignees{/user}","branches_url":"https://api.github.com/repos/gunjan5/libcalico-go/branches{/branch}","tags_url":"https://api.github.com/repos/gunjan5/libcalico-go/tags","blobs_url":"https://api.github.com/repos/gunjan5/libcalico-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gunjan5/libcalico-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gunjan5/libcalico-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/gunjan5/libcalico-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gunjan5/libcalico-go/statuses/{sha}","languages_url":"https://api.github.com/repos/gunjan5/libcalico-go/languages","stargazers_url":"https://api.github.com/repos/gunjan5/libcalico-go/stargazers","contributors_url":"https://api.github.com/repos/gunjan5/libcalico-go/contributors","subscribers_url":"https://api.github.com/repos/gunjan5/libcalico-go/subscribers","subscription_url":"https://api.github.com/repos/gunjan5/libcalico-go/subscription","commits_url":"https://api.github.com/repos/gunjan5/libcalico-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/gunjan5/libcalico-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/gunjan5/libcalico-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/gunjan5/libcalico-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/gunjan5/libcalico-go/contents/{+path}","compare_url":"https://api.github.com/repos/gunjan5/libcalico-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gunjan5/libcalico-go/merges","archive_url":"https://api.github.com/repos/gunjan5/libcalico-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gunjan5/libcalico-go/downloads","issues_url":"https://api.github.com/repos/gunjan5/libcalico-go/issues{/number}","pulls_url":"https://api.github.com/repos/gunjan5/libcalico-go/pulls{/number}","milestones_url":"https://api.github.com/repos/gunjan5/libcalico-go/milestones{/number}","notifications_url":"https://api.github.com/repos/gunjan5/libcalico-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gunjan5/libcalico-go/labels{/name}","releases_url":"https://api.github.com/repos/gunjan5/libcalico-go/releases{/id}","deployments_url":"https://api.github.com/repos/gunjan5/libcalico-go/deployments","created_at":"2016-09-01T20:48:05Z","updated_at":"2016-09-01T20:48:07Z","pushed_at":"2016-09-01T23:03:31Z","git_url":"git://github.com/gunjan5/libcalico-go.git","ssh_url":"git@github.com:gunjan5/libcalico-go.git","clone_url":"https://github.com/gunjan5/libcalico-go.git","svn_url":"https://github.com/gunjan5/libcalico-go","homepage":null,"size":427,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tigera:master","ref":"master","sha":"ad3dc6c75af26bdae34d2366af57f51311a03580","user":{"login":"tigera","id":18633690,"avatar_url":"https://avatars.githubusercontent.com/u/18633690?v=3","gravatar_id":"","url":"https://api.github.com/users/tigera","html_url":"https://github.com/tigera","followers_url":"https://api.github.com/users/tigera/followers","following_url":"https://api.github.com/users/tigera/following{/other_user}","gists_url":"https://api.github.com/users/tigera/gists{/gist_id}","starred_url":"https://api.github.com/users/tigera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tigera/subscriptions","organizations_url":"https://api.github.com/users/tigera/orgs","repos_url":"https://api.github.com/users/tigera/repos","events_url":"https://api.github.com/users/tigera/events{/privacy}","received_events_url":"https://api.github.com/users/tigera/received_events","type":"Organization","site_admin":false},"repo":{"id":63438319,"name":"libcalico-go","full_name":"tigera/libcalico-go","owner":{"login":"tigera","id":18633690,"avatar_url":"https://avatars.githubusercontent.com/u/18633690?v=3","gravatar_id":"","url":"https://api.github.com/users/tigera","html_url":"https://github.com/tigera","followers_url":"https://api.github.com/users/tigera/followers","following_url":"https://api.github.com/users/tigera/following{/other_user}","gists_url":"https://api.github.com/users/tigera/gists{/gist_id}","starred_url":"https://api.github.com/users/tigera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tigera/subscriptions","organizations_url":"https://api.github.com/users/tigera/orgs","repos_url":"https://api.github.com/users/tigera/repos","events_url":"https://api.github.com/users/tigera/events{/privacy}","received_events_url":"https://api.github.com/users/tigera/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tigera/libcalico-go","description":"Golang Calico library functions:  https://www.projectcalico.org","fork":false,"url":"https://api.github.com/repos/tigera/libcalico-go","forks_url":"https://api.github.com/repos/tigera/libcalico-go/forks","keys_url":"https://api.github.com/repos/tigera/libcalico-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tigera/libcalico-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tigera/libcalico-go/teams","hooks_url":"https://api.github.com/repos/tigera/libcalico-go/hooks","issue_events_url":"https://api.github.com/repos/tigera/libcalico-go/issues/events{/number}","events_url":"https://api.github.com/repos/tigera/libcalico-go/events","assignees_url":"https://api.github.com/repos/tigera/libcalico-go/assignees{/user}","branches_url":"https://api.github.com/repos/tigera/libcalico-go/branches{/branch}","tags_url":"https://api.github.com/repos/tigera/libcalico-go/tags","blobs_url":"https://api.github.com/repos/tigera/libcalico-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tigera/libcalico-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tigera/libcalico-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/tigera/libcalico-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tigera/libcalico-go/statuses/{sha}","languages_url":"https://api.github.com/repos/tigera/libcalico-go/languages","stargazers_url":"https://api.github.com/repos/tigera/libcalico-go/stargazers","contributors_url":"https://api.github.com/repos/tigera/libcalico-go/contributors","subscribers_url":"https://api.github.com/repos/tigera/libcalico-go/subscribers","subscription_url":"https://api.github.com/repos/tigera/libcalico-go/subscription","commits_url":"https://api.github.com/repos/tigera/libcalico-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/tigera/libcalico-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/tigera/libcalico-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/tigera/libcalico-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/tigera/libcalico-go/contents/{+path}","compare_url":"https://api.github.com/repos/tigera/libcalico-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tigera/libcalico-go/merges","archive_url":"https://api.github.com/repos/tigera/libcalico-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tigera/libcalico-go/downloads","issues_url":"https://api.github.com/repos/tigera/libcalico-go/issues{/number}","pulls_url":"https://api.github.com/repos/tigera/libcalico-go/pulls{/number}","milestones_url":"https://api.github.com/repos/tigera/libcalico-go/milestones{/number}","notifications_url":"https://api.github.com/repos/tigera/libcalico-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tigera/libcalico-go/labels{/name}","releases_url":"https://api.github.com/repos/tigera/libcalico-go/releases{/id}","deployments_url":"https://api.github.com/repos/tigera/libcalico-go/deployments","created_at":"2016-07-15T17:09:40Z","updated_at":"2016-08-23T08:42:27Z","pushed_at":"2016-09-01T23:03:32Z","git_url":"git://github.com/tigera/libcalico-go.git","ssh_url":"git@github.com:tigera/libcalico-go.git","clone_url":"https://github.com/tigera/libcalico-go.git","svn_url":"https://github.com/tigera/libcalico-go","homepage":null,"size":705,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":41,"forks":9,"open_issues":41,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/119"},"html":{"href":"https://github.com/tigera/libcalico-go/pull/119"},"issue":{"href":"https://api.github.com/repos/tigera/libcalico-go/issues/119"},"comments":{"href":"https://api.github.com/repos/tigera/libcalico-go/issues/119/comments"},"review_comments":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/119/comments"},"review_comment":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tigera/libcalico-go/pulls/119/commits"},"statuses":{"href":"https://api.github.com/repos/tigera/libcalico-go/statuses/7219f329767e805c7b602c920d138ef542890cc9"}}}}
{"actor":{"display_login":"caseydavenport"}}