Skip to content

Commit 376afcf

Browse files
committed
faster randn with ifelse
1 parent c9da7cb commit 376afcf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/random.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ function randmtzig_randn(rng::MersenneTwister=GLOBAL_RNG)
940940
r = randi(rng)
941941
rabs = int64(r>>1) # One bit for the sign
942942
idx = rabs & 0xFF
943-
x = (r&1 != 0x000000000 ? -rabs : rabs)*wi[idx+1]
943+
x = ifelse(r % Bool, -rabs, rabs)*wi[idx+1]
944944
if rabs < ki[idx+1]
945945
return x # 99.3% of the time we return here 1st try
946946
elseif idx == 0

0 commit comments

Comments
 (0)