Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Int63n from Go's rand package called that?

Tags:

go

From the official Go docs:

Int63n returns, as an int64, a non-negative pseudo-random number in [0,n) from the default Source. It panics if n <= 0.

Why is it called Int63n when it returns a 64 bit integer?

like image 380
Johannes Gehrs Avatar asked Oct 20 '25 01:10

Johannes Gehrs


1 Answers

Int63n returns, as an int64, a non-negative pseudo-random number in [0,n) from the default Source

int64 is a 64-bit signed integer type. That means it has 1 sign bit and 63 significant bits. That means that anything returning a non-negative int64 is producing 63 bits of data (the 64th bit, the sign bit, will always have the same value).

like image 70
Adrian Avatar answered Oct 22 '25 03:10

Adrian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!