1
1
module Random
2
2
3
- using Base: dSFMT, Base. GMP. GMP_VERSION
3
+ using Base. dSFMT
4
+ using Base. GMP: GMP_VERSION, Limb
4
5
5
6
export srand,
6
7
rand, rand!,
@@ -391,17 +392,17 @@ if GMP_VERSION.major >= 6
391
392
a:: BigInt # first
392
393
m:: BigInt # range length - 1
393
394
nlimbs:: Int # number of limbs in generated BigInt's
394
- mask:: Culong # applied to the highest limb
395
+ mask:: Limb # applied to the highest limb
395
396
end
396
397
397
398
else
398
399
immutable RangeGeneratorBigInt <: RangeGenerator
399
400
a:: BigInt # first
400
401
m:: BigInt # range length - 1
401
- limbs:: Array{Culong} # buffer to be copied into generated BigInt's
402
- mask:: Culong # applied to the highest limb
402
+ limbs:: Array{Limb} # buffer to be copied into generated BigInt's
403
+ mask:: Limb # applied to the highest limb
403
404
404
- RangeGeneratorBigInt (a, m, nlimbs, mask) = new (a, m, Array (Culong , nlimbs), mask)
405
+ RangeGeneratorBigInt (a, m, nlimbs, mask) = new (a, m, Array (Limb , nlimbs), mask)
405
406
end
406
407
end
407
408
@@ -411,9 +412,9 @@ function RangeGenerator(r::UnitRange{BigInt})
411
412
m = last (r) - first (r)
412
413
m < 0 && error (" range must be non-empty" )
413
414
nd = ndigits (m, 2 )
414
- nlimbs, highbits = divrem (nd, 8 * sizeof (Culong ))
415
+ nlimbs, highbits = divrem (nd, 8 * sizeof (Limb ))
415
416
highbits > 0 && (nlimbs += 1 )
416
- mask = highbits == 0 ? ~ zero (Culong ) : one (Culong )<< highbits - one (Culong )
417
+ mask = highbits == 0 ? ~ zero (Limb ) : one (Limb )<< highbits - one (Limb )
417
418
return RangeGeneratorBigInt (first (r), m, nlimbs, mask)
418
419
end
419
420
@@ -450,7 +451,7 @@ if GMP_VERSION.major >= 6
450
451
x = BigInt ()
451
452
while true
452
453
# note: on CRAY computers, the second argument may be of type Cint (48 bits) and not Clong
453
- xd = ccall ((:__gmpz_limbs_write , :libgmp ), Ptr{Culong }, (Ptr{BigInt}, Clong), & x, g. nlimbs)
454
+ xd = ccall ((:__gmpz_limbs_write , :libgmp ), Ptr{Limb }, (Ptr{BigInt}, Clong), & x, g. nlimbs)
454
455
limbs = pointer_to_array (xd, g. nlimbs)
455
456
rand! (rng, limbs)
456
457
limbs[end ] &= g. mask
468
469
g. limbs[end ] &= g. mask
469
470
ccall ((:__gmpz_import , :libgmp ), Void,
470
471
(Ptr{BigInt}, Csize_t, Cint, Csize_t, Cint, Csize_t, Ptr{Void}),
471
- & x, length (g. limbs), - 1 , sizeof (Culong ), 0 , 0 , & g. limbs)
472
+ & x, length (g. limbs), - 1 , sizeof (Limb ), 0 , 0 , & g. limbs)
472
473
x <= g. m && break
473
474
end
474
475
ccall ((:__gmpz_add , :libgmp ), Void, (Ptr{BigInt}, Ptr{BigInt}, Ptr{BigInt}), & x, & x, & g. a)
0 commit comments