1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* random.c (rb_genrand_ulong_limited): renamed from

rb_rand_internal and now this is public API.

* include/ruby/ruby.h (rb_genrand_ulong_limited): added.

* bignum.c (big_sparse_p): use rb_genrand_ulong_limited.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-09-10 05:44:54 +00:00
parent 7c73db266a
commit 493f721854
4 changed files with 21 additions and 7 deletions

View file

@ -1,3 +1,12 @@
Fri Sep 10 10:33:18 2010 NARUSE, Yui <naruse@ruby-lang.org>
* random.c (rb_genrand_ulong_limited): renamed from
rb_rand_internal and now this is public API.
* include/ruby/ruby.h (rb_genrand_ulong_limited): added.
* bignum.c (big_sparse_p): use rb_genrand_ulong_limited.
Fri Sep 10 13:07:22 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* ext/digest/lib/digest.rb: removed unused exception variable

View file

@ -2214,11 +2214,10 @@ static inline VALUE
big_sparse_p(VALUE x)
{
long c = 0, n = RBIGNUM_LEN(x);
unsigned long rb_rand_internal(unsigned long i);
if ( BDIGITS(x)[rb_rand_internal(n / 2) + n / 4]) c++;
if (c <= 1 && BDIGITS(x)[rb_rand_internal(n / 2) + n / 4]) c++;
if (c <= 1 && BDIGITS(x)[rb_rand_internal(n / 2) + n / 4]) c++;
if ( BDIGITS(x)[rb_genrand_ulong_limited(n / 2) + n / 4]) c++;
if (c <= 1 && BDIGITS(x)[rb_genrand_ulong_limited(n / 2) + n / 4]) c++;
if (c <= 1 && BDIGITS(x)[rb_genrand_ulong_limited(n / 2) + n / 4]) c++;
return (c <= 1) ? Qtrue : Qfalse;
}

View file

@ -559,6 +559,7 @@ VALUE rb_random_bytes(VALUE rnd, long n);
VALUE rb_random_int(VALUE rnd, VALUE max);
unsigned int rb_random_int32(VALUE rnd);
double rb_random_real(VALUE rnd);
unsigned long rb_genrand_ulong_limited(unsigned long i);
/* re.c */
#define rb_memcmp memcmp
int rb_memcicmp(const void*,const void*,long);

View file

@ -875,11 +875,16 @@ limited_big_rand(struct MT *mt, struct RBignum *limit)
return rb_big_norm((VALUE)val);
}
/*
* Returns random unsigned long value in [0, _limit_].
*
* Note that _limit_ is included, and the range of the argument and the
* return value depends on environments.
*/
unsigned long
rb_rand_internal(unsigned long i)
rb_genrand_ulong_limited(unsigned long limit)
{
struct MT *mt = default_mt();
return limited_rand(mt, i);
return limited_rand(default_mt(), limit);
}
unsigned int