mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* random.c (rand_init): ignore higher bits if all they are same as
the lower sign bit. [ruby-core:29292](2) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0f58f9dbe7
commit
f571492922
3 changed files with 18 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Apr 8 07:22:05 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (rand_init): ignore higher bits if all they are same as
|
||||
the lower sign bit. [ruby-core:29292](2)
|
||||
|
||||
Thu Apr 8 07:16:19 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/irb/cmd/help.rb (IRB::ExtendCommand::Help#execute): use RI
|
||||
|
|
8
random.c
8
random.c
|
@ -367,6 +367,7 @@ rand_init(struct MT *mt, VALUE vseed)
|
|||
{
|
||||
volatile VALUE seed;
|
||||
long blen = 0;
|
||||
long fixnum_seed;
|
||||
int i, j, len;
|
||||
unsigned int buf0[SIZEOF_LONG / SIZEOF_INT32 * 4], *buf = buf0;
|
||||
|
||||
|
@ -374,9 +375,12 @@ rand_init(struct MT *mt, VALUE vseed)
|
|||
switch (TYPE(seed)) {
|
||||
case T_FIXNUM:
|
||||
len = 1;
|
||||
buf[0] = (unsigned int)(FIX2ULONG(seed) & 0xffffffff);
|
||||
fixnum_seed = FIX2LONG(seed);
|
||||
buf[0] = (unsigned int)(fixnum_seed & 0xffffffff);
|
||||
#if SIZEOF_LONG > SIZEOF_INT32
|
||||
if ((buf[1] = (unsigned int)(FIX2ULONG(seed) >> 32)) != 0) ++len;
|
||||
if ((long)(int)fixnum_seed != fixnum_seed) {
|
||||
if ((buf[1] = (unsigned int)(fixnum_seed >> 32)) != 0) ++len;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case T_BIGNUM:
|
||||
|
|
|
@ -398,4 +398,11 @@ END
|
|||
assert(st.success?)
|
||||
rescue NotImplementedError, ArgumentError
|
||||
end
|
||||
|
||||
def test_seed
|
||||
bug3104 = '[ruby-core:29292]'
|
||||
rand_1 = Random.new(-1).rand
|
||||
assert_not_equal(rand_1, Random.new((1 << 31) -1).rand, "#{bug3104} (2)")
|
||||
assert_not_equal(rand_1, Random.new((1 << 63) -1).rand, "#{bug3104} (2)")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue