mercredi 15 septembre 2021

Generating random number of N-digits using gmpy2 Library in Python

I have to generate a random number of n-digits using gmpy2 library in python. I know that it is possible to do this using Random library also. But, my requirement force to use this only.

mpz_random function generates random numbers from 0 to N-1. I am not sure how to use this for specific digits.

Here is my code:

import gmpy2

n = 100
rs = gmpy2.random_state(hash(gmpy2.random_state()))
p = gmpy2.mpz_random(rs, n)

print(p)



Aucun commentaire:

Enregistrer un commentaire