@@ -521,27 +521,6 @@ impl FromStrRadix for BigUint {
521521 }
522522}
523523
524- trait RandBigUInt {
525- /// Generate a random BigUint of the given bit size.
526- fn gen_biguint ( & mut self , bit_size : uint ) -> BigUint ;
527- }
528-
529- impl < R : Rng > RandBigUInt for R {
530- /// Generate a random BigUint of the given bit size.
531- fn gen_biguint ( & mut self , bit_size : uint ) -> BigUint {
532- let ( digits, rem) = bit_size. div_rem ( & BigDigit :: bits) ;
533- let mut data = vec:: with_capacity ( digits+1 ) ;
534- for _ in range ( 0 , digits) {
535- data. push ( self . gen ( ) ) ;
536- }
537- if rem > 0 {
538- let final_digit: BigDigit = self . gen ( ) ;
539- data. push ( final_digit >> ( BigDigit :: bits - rem) ) ;
540- }
541- return BigUint :: new ( data) ;
542- }
543- }
544-
545524impl BigUint {
546525 /// Creates and initializes an BigUint.
547526 #[ inline]
@@ -1074,12 +1053,29 @@ impl FromStrRadix for BigInt {
10741053}
10751054
10761055trait RandBigInt {
1056+ /// Generate a random BigUint of the given bit size.
1057+ fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
1058+
10771059 /// Generate a random BigInt of the given bit size.
10781060 fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
10791061}
10801062
10811063impl<R: Rng> RandBigInt for R {
10821064 /// Generate a random BigUint of the given bit size.
1065+ fn gen_biguint(&mut self, bit_size: uint) -> BigUint {
1066+ let (digits, rem) = bit_size.div_rem(&BigDigit::bits);
1067+ let mut data = vec::with_capacity(digits+1);
1068+ for _ in range(0, digits) {
1069+ data.push(self.gen());
1070+ }
1071+ if rem > 0 {
1072+ let final_digit: BigDigit = self.gen();
1073+ data.push(final_digit >> (BigDigit::bits - rem));
1074+ }
1075+ return BigUint::new(data);
1076+ }
1077+
1078+ /// Generate a random BigInt of the given bit size.
10831079 fn gen_bigint(&mut self, bit_size: uint) -> BigInt {
10841080 // Generate a random BigUint...
10851081 let biguint = self.gen_biguint(bit_size);
0 commit comments