{"id":19666600,"url":"https://github.com/xaionaro-go/weightedshuffle","last_synced_at":"2025-02-27T04:17:24.932Z","repository":{"id":57642920,"uuid":"437625288","full_name":"xaionaro-go/weightedshuffle","owner":"xaionaro-go","description":"Shuffle slice with weighted position preference","archived":false,"fork":false,"pushed_at":"2021-12-13T01:07:40.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T02:45:28.540Z","etag":null,"topics":["go","golang","order","preference","rand","random","reorder","shuffle","slice","sort","weight","weighted"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaionaro-go.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-12T18:31:18.000Z","updated_at":"2023-04-14T06:30:37.000Z","dependencies_parsed_at":"2022-08-27T21:52:16.794Z","dependency_job_id":null,"html_url":"https://github.com/xaionaro-go/weightedshuffle","commit_stats":null,"previous_names":["xaionaro-go/weightedrandsort"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fweightedshuffle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fweightedshuffle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fweightedshuffle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Fweightedshuffle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaionaro-go","download_url":"https://codeload.github.com/xaionaro-go/weightedshuffle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240976185,"owners_count":19887439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","order","preference","rand","random","reorder","shuffle","slice","sort","weight","weighted"],"created_at":"2024-11-11T16:28:14.851Z","updated_at":"2025-02-27T04:17:24.907Z","avatar_url":"https://github.com/xaionaro-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/xaionaro-go/weightedshuffle?status.svg)](https://pkg.go.dev/github.com/xaionaro-go/weightedshuffle?tab=doc)\n\n# Shuffle, but with position preference\n\nThis package allows to (semi-)randomly order a slice with weight-based preference to get closer to the beginning of the slice.\n\nFor example, slice `[1, 2, 3, 4]` with weights `[0, 1, 9, 10]` most likely will result into `[4, 3, 2, 1]` or `[3, 4, 2, 1]`:\n* `1` is always in the end because it has zero-weight,\n* `2` most likely goes after `3` and `4` because it has much lower weight\n* while `4` and `3` have almost the same weight so they will have quite random order relatively to each other.\n\n# Performance\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/xaionaro-go/weightedshuffle\ncpu: Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz\nBenchmarkShuffle/0/Shuffle-12         \t 6839139\t       180.2 ns/op\t     120 B/op\t       3 allocs/op\nBenchmarkShuffle/0/ShuffleInplace-12  \t 8649206\t       139.8 ns/op\t      56 B/op\t       2 allocs/op\nBenchmarkShuffle/1/Shuffle-12         \t 4564108\t       262.4 ns/op\t     144 B/op\t       4 allocs/op\nBenchmarkShuffle/1/ShuffleInplace-12  \t11854474\t        87.38 ns/op\t      56 B/op\t       2 allocs/op\nBenchmarkShuffle/10/Shuffle-12        \t 1289701\t       954.4 ns/op\t     424 B/op\t      10 allocs/op\nBenchmarkShuffle/10/ShuffleInplace-12 \t 1888671\t       627.1 ns/op\t     120 B/op\t       5 allocs/op\nBenchmarkShuffle/100/Shuffle-12       \t  114979\t      9761 ns/op\t    2216 B/op\t      13 allocs/op\nBenchmarkShuffle/100/ShuffleInplace-12         \t  127245\t      9563 ns/op\t     120 B/op\t       5 allocs/op\nBenchmarkShuffle/1000/Shuffle-12               \t    7822\t    132306 ns/op\t   16552 B/op\t      16 allocs/op\nBenchmarkShuffle/1000/ShuffleInplace-12        \t    2047\t    613564 ns/op\t     120 B/op\t       5 allocs/op\nBenchmarkShuffle/10000/Shuffle-12              \t     688\t   1745520 ns/op\t  386473 B/op\t      25 allocs/op\nBenchmarkShuffle/10000/ShuffleInplace-12       \t      19\t  59876093 ns/op\t     120 B/op\t       5 allocs/op\nBenchmarkShuffle/100000/Shuffle-12             \t      60\t  23312442 ns/op\t 4654532 B/op\t      35 allocs/op\nBenchmarkShuffle/1000000/Shuffle-12            \t       4\t 282116172 ns/op\t45188534 B/op\t      45 allocs/op\nPASS\nok  \tgithub.com/xaionaro-go/weightedshuffle\t20.833s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Fweightedshuffle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaionaro-go%2Fweightedshuffle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Fweightedshuffle/lists"}