mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-03 19:03:24 +00:00
Improve random bignum generation
* src/bignum.c (get_random_limb, get_random_limb_lim) (get_random_bignum): New functions, for more-efficient generation of random bignums without using Frem etc. * src/fns.c (get_random_fixnum): New function. (Frandom): Use it, and get_random_bignum. Be consistent about signalling nonpositive integer arguments; since zero is invalid, Qnatnump is not quite right here. * src/sysdep.c (get_random_ulong): New function.
This commit is contained in:
parent
31a2428d6f
commit
2ef037c0dd
5 changed files with 132 additions and 50 deletions
10
src/sysdep.c
10
src/sysdep.c
|
@ -2200,6 +2200,16 @@ get_random (void)
|
|||
return val & INTMASK;
|
||||
}
|
||||
|
||||
/* Return a random unsigned long. */
|
||||
unsigned long int
|
||||
get_random_ulong (void)
|
||||
{
|
||||
unsigned long int r = 0;
|
||||
for (int i = 0; i < (ULONG_WIDTH + RAND_BITS - 1) / RAND_BITS; i++)
|
||||
r = random () ^ (r << RAND_BITS) ^ (r >> (ULONG_WIDTH - RAND_BITS));
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
/* Approximate snprintf as best we can on ancient hosts that lack it. */
|
||||
int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue