google / google/leveldb

Random never return 0

Open
#208 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
39.4k
Forks
8.2k
PR merge metrics
No merged PRs in 30d

Description

Original [issue 202](https://code.google.com/p/leveldb/issues/detail?id=202) created by me@sunchangming.com on 2013-08-29T16:25:45.000Z:

In util/ random.h, we are computing seed_ = (seed_ \* A) % M, where M = 231-1, and the seed_ cannot be zero.

So, Random::Next() function never returns zero.

The member function of this class

``` c++
uint32_t Uniform(int n) { return Next() % n; }
```

returns a uniformly distributed value in the range [1..n-1] , not [0..n-1]

patch:
change the last line of function Next() from

``` c++
return seed_;
```

to

``` c++
return seed_ - 1;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.