Skip to content

Commit 29716c5

Browse files
committed
docs: minor README updates
1 parent fcfd837 commit 29716c5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44
[![Go Report Card](https://goreportcard.com/badge/github.com/mroth/weightedrand)](https://goreportcard.com/report/github.com/mroth/weightedrand)
55
[![GoDoc](https://godoc.org/github.com/mroth/weightedrand?status.svg)](https://godoc.org/github.com/mroth/weightedrand)
66

7-
Randomly select an element from some kind of list, with the chances of each
8-
element to be selected not being equal, but defined by relative "weights" (or
9-
probabilities). This is called weighted random selection.
7+
> Fast weighted random selection for Go.
108
11-
The existing Go library that has a generic implementation of this is
12-
[`github.com/jmcvetta/randutil`][1], which optimizes for the single operation
13-
case. In contrast, this library creates a presorted cache optimized for binary
14-
search, allowing repeated selections from the same set to be significantly
15-
faster, especially for large data sets.
16-
17-
[1]: https://github.com/jmcvetta/randutil
9+
Randomly selects an element from some kind of list, where the chances of each
10+
element to be selected are not equal, but rather defined by relative "weights"
11+
(or probabilities). This is called weighted random selection.
1812

1913
## Usage
2014

@@ -44,8 +38,17 @@ func main() {
4438
```
4539

4640
## Benchmarks
47-
Comparison of this library versus `randutil.ChooseWeighted`. For large numbers
48-
of samplings from large collections, `weightedrand` will be quicker.
41+
42+
The existing Go library that has a comparable implementation of this is
43+
[`github.com/jmcvetta/randutil`][1], which optimizes for the single operation
44+
case. In contrast, this library creates a presorted cache optimized for binary
45+
search, allowing repeated selections from the same set to be significantly
46+
faster, especially for large data sets.
47+
48+
[1]: https://github.com/jmcvetta/randutil
49+
50+
Comparison of this library versus `randutil.ChooseWeighted`. For repeated
51+
samplings from large collections, `weightedrand` will be much quicker.
4952

5053
| Num choices | `randutil` | `weightedrand` |
5154
| ----------: | ------------: | -------------: |
@@ -61,15 +64,16 @@ right choice! If you are only picking from the same distribution once,
6164
`randutil` will be faster. `weightedrand` optimizes for repeated calls at the
6265
expense of some setup time and memory storage.
6366

67+
*Update: Starting in `v0.3.0` weightedrand can now scale linearly to take
68+
advantage of multiple CPU cores in parallel, making it even faster. See
69+
[PR#2](https://github.com/mroth/weightedrand/pull/2) for details.*
70+
6471
## Caveats
6572

6673
Note this uses `math/rand` instead of `crypto/rand`, as it is optimized for
67-
performance, not cryptographically secure implementation.
68-
69-
Relies on global rand for determinism, therefore, don't forget to seed random!
74+
performance, not a cryptographically secure implementation.
7075

7176
## Credits
7277

73-
The algorithm used in this library (as well as the one used in randutil) comes
74-
from:
75-
https://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/
78+
To better understand the algorithm used in this library (as well as the one used
79+
in randutil) check out this great blog post: [Weighted random generation in Python](https://eli.thegreenplace.net/2010/01/22/weighted-random-generation-in-python/).

0 commit comments

Comments
 (0)