{"repo":"mroth/weightedrand","free":true,"listed":false,"github":"https://github.com/mroth/weightedrand","clone":"git clone https://github.com/mroth/weightedrand.git","description":"⚖️ Fast weighted random selection for Go","language":"Go","stars":416,"topics":["weighted-random","random","sampling","golang","go","go-module"],"license":"MIT","category":"dev-tools","readme_excerpt":"weightedrand :balance scale: Fast weighted random selection for Go. Randomly selects an element from some kind of list, where the chances of each element to be selected are not equal, but rather defined by relative \"weights\" (or probabilities). This is called weighted random selection. Usage Performance The existing Go library that has a comparable implementation of this is [ github.com/jmcvetta/randutil ][1], which optimizes for the single operation case. In contrast, this library creates a presorted cache optimized for binary search, allowing repeated selections from the same set to be significantly faster, especially for large data sets. [1]: https://github.com/jmcvetta/randutil Comparison of this library versus randutil.ChooseWeighted on my workstation. For repeated samplings from large collections, weightedrand will be much quicker: Num choices randutil weightedrand weightedrand -cpu=8 ----------: -------------: -------------: ---------------------: 10 201 ns/op 38 ns/op 2.9 ns/op 100 267 ns/op 51 ns/op 4.1 ns/op 1,000 1012 ns/op 67 ns/op 5.4 ns/op 10,000 8683 ns/op 83 ns/op 6.9 ns/op 100,000 123500 ns/op 105 ns/op 12.0 ns/op 1,000,000 2399614 ns/op 218 ns/op 17.2 ns/op 10,000,000 26804440 ns/op 432 ns/op 35.1 ns/op : Since v0.3.0 weightedrand can efficiently utilize a single Chooser across multiple CPU cores in parallel, making it even faster in overall throughput. See PR#2 for details. Informal benchmarks conducted on an Intel Xeon W-2140B CPU (8 core @ 3.2GHz, hyperth","default_branch":null,"files":null,"tree":[],"storefront":"/r/mroth","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/mroth/weightedrand/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}