How to obtain a BigInt random number within a range in julia? -
I need to get a random number between julia 1 and one What is the fastest way to do this? (Your number should be distributed evenly.) Thank you! It is available after all if you use ccall I'm sure that at some point it Easy will happen, but now there is a way to do this, I have not found any way to use it from the base, but if these things change then it will be amended. For this work, 2 calls need to be made from GMP's docs, I have selected mpz_urandomm â ???? Function: Generate a uniform random integer in zero mpz_urandomm (mpz_t rop, gmp_randstate_t state, const mpz_t n) range 0 to n-1, inclusive. The variable status should be started before starting this function by calling a GMP_Randitate Function (Random State Initialization). You have to start the random number generator first, I did not do it better, with some sophisticated updates. â ???? Function: Start the state with the default gmp_randinit_default (gmp_randstate_t position) with a default algorithm This will be an agreement between speed and randomness, and is recommended for applications with special needs. Currently it is gmp_randinit_mt. is not a great way to declare gmp_randstate_t, just declare a bigger buffer It is important otherwise there is a default default. Create a Bigget, X to store the result Maximize the set Julia & gt; y = BigInt (2) ^ 1000 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 generate random X (ccall: (__gmpz_urandomm ,: libgmp), zero, (ptr {bigint}, ptr {Uint8}, pt {buddhi}}, & amp; verify Julia & gt; X 9301165293246235069759966068146313776551258669855356477271940698500929939755418247622530571466332330697816620308003246225290293476785304004840090056840661553451916748315356563734257724978000166406621823207925733850455027807451108123161768212073821382033500073069184011344280494573919716117539236653172 etc ... Julia & gt; ; X50735997231132174460356060582033623246103269486857076745782056181899824261005156026806402301410187583281612784697598359436783609527954405126803804 24413847653984694781421269745198616340362470820037933917709243387214511018480191308767310495781355601069937334945556566243556239048498564021992916827796124 bigInt , but I find it in the documentation 'how it can be done. The code I thought to be the code below would work:
julia & gt; RAND (BigTint (1): Bigint (2 ^ 1000)) Error: Random integer split error in JL on JL: 158 random.jl in rand: 178 random.jl in Rand: 187 < P> Edit : Greg will be wrapped around
2 ^ 1000 , in fact, the
2 ^ 1000 result occurs in zero, So the above code is wrong. But
does not use BigInt (2) ^ 1000 :
julia> RAND (BigTint (1): BigInant (2) ^ 1000) Error: Convert to GMPJL in the AxAct error (Range at 108 Colon. JL: 38 Julia & gt; RAND (BigTint (1): BigInant (2) ^ BigInant (1000) error: Converted to gmp.jl in incircle (): at 108.Colon at range.jl: 38
GMP support
ccall method
start RNG
Julia & gt; Buffer = array (Uint8,32); Julia & gt; Ccall ((: __gmp_randinit_default ,: libgmp), zero, (PTR {Uint8}), buffer;
Generate a random number
julia & gt; X = BigInant (0) 0
Julia & gt;
Julia & gt;
Comments
Post a Comment