3
3
4
4
use integer:: Integer ;
5
5
use num_traits:: { FromPrimitive , One , ToPrimitive , Zero } ;
6
+ use once_cell:: sync:: Lazy ;
6
7
use rand:: rngs:: StdRng ;
7
8
use rand:: SeedableRng ;
8
9
@@ -12,12 +13,9 @@ use crate::bigrand::RandBigInt;
12
13
use crate :: Sign :: Plus ;
13
14
use crate :: { BigInt , BigUint , IntoBigUint } ;
14
15
15
- lazy_static ! {
16
- pub ( crate ) static ref BIG_1 : BigUint = BigUint :: one( ) ;
17
- pub ( crate ) static ref BIG_2 : BigUint = BigUint :: from_u64( 2 ) . unwrap( ) ;
18
- pub ( crate ) static ref BIG_3 : BigUint = BigUint :: from_u64( 3 ) . unwrap( ) ;
19
- pub ( crate ) static ref BIG_64 : BigUint = BigUint :: from_u64( 64 ) . unwrap( ) ;
20
- }
16
+ pub ( crate ) const BIG_1 : Lazy < BigUint > = Lazy :: new ( || BigUint :: one ( ) ) ;
17
+ pub ( crate ) const BIG_2 : Lazy < BigUint > = Lazy :: new ( || BigUint :: from_u64 ( 2 ) . unwrap ( ) ) ;
18
+ pub ( crate ) const BIG_64 : Lazy < BigUint > = Lazy :: new ( || BigUint :: from_u64 ( 64 ) . unwrap ( ) ) ;
21
19
22
20
const PRIMES_A : u64 = 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 37 ;
23
21
const PRIMES_B : u64 = 29 * 31 * 41 * 43 * 47 * 53 ;
@@ -439,8 +437,7 @@ mod tests {
439
437
440
438
use crate :: biguint:: ToBigUint ;
441
439
442
- lazy_static ! {
443
- static ref PRIMES : Vec <& ' static str > = vec![
440
+ const PRIMES : & ' static [ & ' static str ] = & [
444
441
"2" ,
445
442
"3" ,
446
443
"5" ,
@@ -469,85 +466,84 @@ mod tests {
469
466
"9850501549098619803069760025035903451269934817616361666987073351061430442874302652853566563721228910201656997576599" , // E-382: 2^382-105
470
467
"42307582002575910332922579714097346549017899709713998034217522897561970639123926132812109468141778230245837569601494931472367" , // Curve41417: 2^414-17
471
468
"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151" , // E-521: 2^521-1
472
- ] ;
473
-
474
- static ref COMPOSITES : Vec <& ' static str > = vec![
475
- "0" ,
476
- "1" ,
477
-
478
- "21284175091214687912771199898307297748211672914763848041968395774954376176754" ,
479
- "6084766654921918907427900243509372380954290099172559290432744450051395395951" ,
480
- "84594350493221918389213352992032324280367711247940675652888030554255915464401" ,
481
- "82793403787388584738507275144194252681" ,
482
-
483
- // Arnault, "Rabin-Miller Primality Test: Composite Numbers Which Pass It",
484
- // Mathematics of Computation, 64(209) (January 1995), pp. 335-361.
485
- "1195068768795265792518361315725116351898245581" , // strong pseudoprime to prime bases 2 through 29
486
- // strong pseudoprime to all prime bases up to 200
487
- "8038374574536394912570796143419421081388376882875581458374889175222974273765333652186502336163960045457915042023603208766569966760987284043965408232928738791850869166857328267761771029389697739470167082304286871099974399765441448453411558724506334092790222752962294149842306881685404326457534018329786111298960644845216191652872597534901" ,
488
-
489
- // Extra-strong Lucas pseudoprimes. https://oeis.org/A217719
490
- "989" ,
491
- "3239" ,
492
- "5777" ,
493
- "10877" ,
494
- "27971" ,
495
- "29681" ,
496
- "30739" ,
497
- "31631" ,
498
- "39059" ,
499
- "72389" ,
500
- "73919" ,
501
- "75077" ,
502
- "100127" ,
503
- "113573" ,
504
- "125249" ,
505
- "137549" ,
506
- "137801" ,
507
- "153931" ,
508
- "155819" ,
509
- "161027" ,
510
- "162133" ,
511
- "189419" ,
512
- "218321" ,
513
- "231703" ,
514
- "249331" ,
515
- "370229" ,
516
- "429479" ,
517
- "430127" ,
518
- "459191" ,
519
- "473891" ,
520
- "480689" ,
521
- "600059" ,
522
- "621781" ,
523
- "632249" ,
524
- "635627" ,
525
-
526
- "3673744903" ,
527
- "3281593591" ,
528
- "2385076987" ,
529
- "2738053141" ,
530
- "2009621503" ,
531
- "1502682721" ,
532
- "255866131" ,
533
- "117987841" ,
534
- "587861" ,
535
-
536
- "6368689" ,
537
- "8725753" ,
538
- "80579735209" ,
539
- "105919633" ,
540
- ] ;
541
-
542
- // Test Cases from #51
543
- static ref ISSUE_51 : Vec <& ' static str > = vec![
544
- "1579751" ,
545
- "1884791" ,
546
- "3818929" ,
547
- "4080359" ,
548
- "4145951" ,
549
- ] ;
550
- }
469
+ ] ;
470
+
471
+ const COMPOSITES : & ' static [ & ' static str ] = & [
472
+ "0" ,
473
+ "1" ,
474
+
475
+ "21284175091214687912771199898307297748211672914763848041968395774954376176754" ,
476
+ "6084766654921918907427900243509372380954290099172559290432744450051395395951" ,
477
+ "84594350493221918389213352992032324280367711247940675652888030554255915464401" ,
478
+ "82793403787388584738507275144194252681" ,
479
+
480
+ // Arnault, "Rabin-Miller Primality Test: Composite Numbers Which Pass It",
481
+ // Mathematics of Computation, 64(209) (January 1995), pp. 335-361.
482
+ "1195068768795265792518361315725116351898245581" , // strong pseudoprime to prime bases 2 through 29
483
+ // strong pseudoprime to all prime bases up to 200
484
+ "8038374574536394912570796143419421081388376882875581458374889175222974273765333652186502336163960045457915042023603208766569966760987284043965408232928738791850869166857328267761771029389697739470167082304286871099974399765441448453411558724506334092790222752962294149842306881685404326457534018329786111298960644845216191652872597534901" ,
485
+
486
+ // Extra-strong Lucas pseudoprimes. https://oeis.org/A217719
487
+ "989" ,
488
+ "3239" ,
489
+ "5777" ,
490
+ "10877" ,
491
+ "27971" ,
492
+ "29681" ,
493
+ "30739" ,
494
+ "31631" ,
495
+ "39059" ,
496
+ "72389" ,
497
+ "73919" ,
498
+ "75077" ,
499
+ "100127" ,
500
+ "113573" ,
501
+ "125249" ,
502
+ "137549" ,
503
+ "137801" ,
504
+ "153931" ,
505
+ "155819" ,
506
+ "161027" ,
507
+ "162133" ,
508
+ "189419" ,
509
+ "218321" ,
510
+ "231703" ,
511
+ "249331" ,
512
+ "370229" ,
513
+ "429479" ,
514
+ "430127" ,
515
+ "459191" ,
516
+ "473891" ,
517
+ "480689" ,
518
+ "600059" ,
519
+ "621781" ,
520
+ "632249" ,
521
+ "635627" ,
522
+
523
+ "3673744903" ,
524
+ "3281593591" ,
525
+ "2385076987" ,
526
+ "2738053141" ,
527
+ "2009621503" ,
528
+ "1502682721" ,
529
+ "255866131" ,
530
+ "117987841" ,
531
+ "587861" ,
532
+
533
+ "6368689" ,
534
+ "8725753" ,
535
+ "80579735209" ,
536
+ "105919633" ,
537
+ ] ;
538
+
539
+ // Test Cases from #51
540
+ const ISSUE_51 : & ' static [ & ' static str ] = & [
541
+ "1579751" ,
542
+ "1884791" ,
543
+ "3818929" ,
544
+ "4080359" ,
545
+ "4145951" ,
546
+ ] ;
551
547
552
548
#[ test]
553
549
fn test_primes ( ) {
0 commit comments