Java,BigInteger
samdevlop
Messages postés
150
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour à tous,
j'aurais besoin d'un code en java me premettant de générer un grand nombre entier aléatoire en spécifiant la valeur max que prend ce nombre.Autrement dit, je cherche l'équivalent de ce code (qui concerne les nombres entiers)mais pour les 'BigInteger':
////////
Random r=new Random();
int rand = r.nextInt (10);
//////// rand sera < 10
merci d'avance et bon courage à tous
j'aurais besoin d'un code en java me premettant de générer un grand nombre entier aléatoire en spécifiant la valeur max que prend ce nombre.Autrement dit, je cherche l'équivalent de ce code (qui concerne les nombres entiers)mais pour les 'BigInteger':
////////
Random r=new Random();
int rand = r.nextInt (10);
//////// rand sera < 10
merci d'avance et bon courage à tous
A voir également:
- Biginteger java
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages
2 réponses
Salut,
Il y a ceci dans la doc...
https://docs.oracle.com/javase/6/docs/api/
Mais peut_être l'as tu déjà vu?
BigInteger
public BigInteger(int numBits,
Random rnd)
Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits - 1), inclusive. The uniformity of the distribution assumes that a fair source of random bits is provided in rnd. Note that this constructor always constructs a non-negative BigInteger.
Parameters:
numBits - maximum bitLength of the new BigInteger.
rnd - source of randomness to be used in computing the new BigInteger.
Throws:
IllegalArgumentException - numBits is negative.
See Also:
bitLength()
--------------------------------------------------------------------------------
BigInteger
public BigInteger(int bitLength,
int certainty,
Random rnd)
Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.
It is recommended that the probablePrime method be used in preference to this constructor unless there is a compelling need to specify a certainty.
Parameters:
bitLength - bitLength of the returned BigInteger.
certainty - a measure of the uncertainty that the caller is willing to tolerate. The probability that the new BigInteger represents a prime number will exceed (1 - 1/2certainty). The execution time of this constructor is proportional to the value of this parameter.
rnd - source of random bits used to select candidates to be tested for primality.
Throws:
ArithmeticException - bitLength < 2.
See Also:
bitLength()
Cordialement,
Dan
Il y a ceci dans la doc...
https://docs.oracle.com/javase/6/docs/api/
Mais peut_être l'as tu déjà vu?
BigInteger
public BigInteger(int numBits,
Random rnd)
Constructs a randomly generated BigInteger, uniformly distributed over the range 0 to (2numBits - 1), inclusive. The uniformity of the distribution assumes that a fair source of random bits is provided in rnd. Note that this constructor always constructs a non-negative BigInteger.
Parameters:
numBits - maximum bitLength of the new BigInteger.
rnd - source of randomness to be used in computing the new BigInteger.
Throws:
IllegalArgumentException - numBits is negative.
See Also:
bitLength()
--------------------------------------------------------------------------------
BigInteger
public BigInteger(int bitLength,
int certainty,
Random rnd)
Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.
It is recommended that the probablePrime method be used in preference to this constructor unless there is a compelling need to specify a certainty.
Parameters:
bitLength - bitLength of the returned BigInteger.
certainty - a measure of the uncertainty that the caller is willing to tolerate. The probability that the new BigInteger represents a prime number will exceed (1 - 1/2certainty). The execution time of this constructor is proportional to the value of this parameter.
rnd - source of random bits used to select candidates to be tested for primality.
Throws:
ArithmeticException - bitLength < 2.
See Also:
bitLength()
Cordialement,
Dan
samdevlop
Messages postés
150
Statut
Membre
5
merci pour ta reponse, mais je n'arrive pas a trouver le tuto que tu m'as indiqué. en plus je vais choisir quoi comme rnd.
Salut,
Tu cliques sur ce lien (qui n'est pas un tuto, mais la doc Sun Java Platform SE 6)
Ensuite dans la fenêtre All Classes tu recherches la classe BigInteger que tu cliques.
En faisant défiler cette nouvelle fenêtre (class BigInteger) jusqu'à trouver Constructor Detail, tu obtiens tous les cas dont :
public BigInteger(int numBits,
Random rnd)
Cordialement,
Dan
Tu cliques sur ce lien (qui n'est pas un tuto, mais la doc Sun Java Platform SE 6)
Ensuite dans la fenêtre All Classes tu recherches la classe BigInteger que tu cliques.
En faisant défiler cette nouvelle fenêtre (class BigInteger) jusqu'à trouver Constructor Detail, tu obtiens tous les cas dont :
public BigInteger(int numBits,
Random rnd)
Cordialement,
Dan