Java,BigInteger

Fermé
samdevlop Messages postés 142 Date d'inscription lundi 10 septembre 2007 Statut Membre Dernière intervention 27 mai 2010 - 13 mai 2009 à 21:25
 Utilisateur anonyme - 14 mai 2009 à 18:30
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
A voir également:

2 réponses

Utilisateur anonyme
14 mai 2009 à 03:44
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
0
samdevlop Messages postés 142 Date d'inscription lundi 10 septembre 2007 Statut Membre Dernière intervention 27 mai 2010 5
14 mai 2009 à 17:01
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.
0
Utilisateur anonyme
14 mai 2009 à 18:30
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
0