Skip to content

Commit

Permalink
Update 5.1.md
Browse files Browse the repository at this point in the history
In the Random(a,b) function (line 25) the for loop should go from 0 to bits - 1 (line 29) because we want to generate numbers from range 0 to 2 ^ bits (not 2 ^ bits + 1). Also there should be left shift operation (<<). (line 31)
  • Loading branch information
devamgupta authored and Peng-Yu Chen committed May 3, 2021
1 parent 17066eb commit 8a9de60
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/Chap05/5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ RANDOM(a, b)
range = b - a
bits = ceil(log(2, range))
result = 0
for i = 1 to bits
for i = 0 to bits - 1
r = RANDOM(0, 1)
result = result + r >> i
result = result + r << i
if result > range
return RANDOM(a, b)
else return a + result
Expand Down

0 comments on commit 8a9de60

Please sign in to comment.