This method has the following call sequence:
BN.rand(bits [, fill [, odd]]) -> aBN
If we look at the code at
|
bottom = (odd == Qtrue) ? 1 : 0; |
we see an explicit check for == Qtrue. This means passing any other value that is true-ish in Ruby is interpreted as false:
$ ruby -ropenssl -e 'p OpenSSL::BN.rand(8, 0, 1).to_i'
140
$ ruby -ropenssl -e 'p OpenSSL::BN.rand(8, 0, 1).to_i'
158
Here the first line generated an even number, even though we pass in a true-ish value.
bottom = RTEST(odd) ? 1 : 0;
I think this should be the preferred way.
If this is intentional (or should be kept to preserve behaviour), it should probably be reflected in the docs.
This method has the following call sequence:
If we look at the code at
openssl/ext/openssl/ossl_bn.c
Line 821 in ed948ea
we see an explicit check for
== Qtrue. This means passing any other value that is true-ish in Ruby is interpreted asfalse:Here the first line generated an even number, even though we pass in a true-ish value.
I think this should be the preferred way.
If this is intentional (or should be kept to preserve behaviour), it should probably be reflected in the docs.