@@ -521,27 +521,6 @@ impl FromStrRadix for BigUint {
521
521
}
522
522
}
523
523
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
-
545
524
impl BigUint {
546
525
/// Creates and initializes an BigUint.
547
526
#[ inline]
@@ -1074,12 +1053,29 @@ impl FromStrRadix for BigInt {
1074
1053
}
1075
1054
1076
1055
trait RandBigInt {
1056
+ /// Generate a random BigUint of the given bit size.
1057
+ fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
1058
+
1077
1059
/// Generate a random BigInt of the given bit size.
1078
1060
fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
1079
1061
}
1080
1062
1081
1063
impl<R: Rng> RandBigInt for R {
1082
1064
/// 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.
1083
1079
fn gen_bigint(&mut self, bit_size: uint) -> BigInt {
1084
1080
// Generate a random BigUint...
1085
1081
let biguint = self.gen_biguint(bit_size);
0 commit comments