// Written by Alexander Stocko // // To the extent possible under law, the author has dedicated all copyright // and related and neighboring rights to this software to the public domain // worldwide. This software is distributed without any warranty. // // See extern crate xorshift; use xorshift::*; pub fn iter_eq(i: I, j: J) -> bool where I: IntoIterator, J: IntoIterator, I::Item: Eq { // make sure the iterators have equal length let mut i = i.into_iter(); let mut j = j.into_iter(); loop { match (i.next(), j.next()) { (Some(ref ei), Some(ref ej)) if ei == ej => {} (None, None) => return true, _ => return false, } } } #[test] fn test_xorshift128_sm64_seed() { let seed: u64 = 1477779739382793006; let t_vals: Vec = vec![3734360756937350019, 5028964947479250132, 16375665863640395736, 2386892914202662210, 15199834089667825831, 17769497452517632314, 12680721629729812030, 15564531140416851055, 11097790028826869390, 8478402252556281388, 3938630131836463627, 13482979509801512434, 16826253285660065403, 16110278797893572156, 11536506513440789906, 7639752116656372922, 1046059652735550751, 11521404418567128807, 8529751223868693606, 12997998284187723322, 18322790657117269355, 18201999538031917662, 8634445242778461938, 8466277913022430845, 1885031811907404633, 2264739358779356253, 15094530947316096845, 18137559477068189932, 2537656743610107989, 5138871238406804931, 15183155499907296889, 11867367639895528720, 10562715032360782312, 16664395174510276263, 6997805435275293159, 16972921566667776634, 1074247737508005038, 13740693935060571294, 15816257217974485909, 4064315281268274790, 7629852493902720019, 12203064001556445231, 6322785606105448062, 13059284569762622579, 7165340459966923980, 11277658567464979261, 12727441884037292431, 4035144520916529304, 367719864125592010, 10625882457741862049]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xorshift128 = Rand::rand(&mut sm); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); } #[test] fn test_xoroshiro128_sm64_seed() { let seed: u64 = 1477780064718404645; let t_vals: Vec = vec![161743971435277218, 12749638389516825946, 4146736784021417053, 11394733814739543922, 5919433169786178858, 4241863456358946179, 7153495629702943020, 6615420010493371247, 9952100663899464852, 14672847684171515009, 17113800272934008423, 16403311139858716934, 12215484346000886377, 14238806683115497214, 13910142693410592070, 7724144857223886361, 9075733398169617904, 5634930714536464900, 2733942052901160118, 17693715793714424022, 8137122508671055182, 6415747618330055320, 15705975534504365925, 5868048410449252447, 9108959133630137736, 7483243276722213562, 14868796904872558029, 6313023836281617677, 6649336199478439294, 16149102996888215516, 3727991758618490683, 2320694756706062361, 12162126961292846971, 15484054774226706687, 16851698291513424180, 6211763121824466039, 1443411643584089856, 11814931554953919683, 1229846429463909320, 834914031011571225, 13014431014741371058, 5432524950931051905, 8352162180100044457, 4423136763541234055, 12211563008565317702, 10719456616463860877, 2097044165121537405, 10275641484510235258, 1951146658863428296, 9961210433054140615]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xoroshiro128 = Rand::rand(&mut sm); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); } #[test] fn test_xorshift1024_sm64_seed() { let seed: u64 = 1477780182365762752; let t_vals: Vec = vec![7318853836271591753, 9274623446119407168, 7680446314077579600, 17082585102123344681, 17137567043538026650, 7937722105151092774, 11116912673301324510, 11068800607127969389, 6297635292564734785, 13519641119573099720, 12130373279879659717, 14360720272095099140, 6871195285874576390, 3810992938594941976, 702052121116926886, 9924167817777718969, 11779260473802976832, 6704443352799728691, 8135383811252218836, 8895372961824568755, 10286073723938788972, 7092470943059603460, 7965246990187368385, 7210101736085100830, 12609608380247765674, 16734156809779408751, 17685015894048411994, 12967080891160409700, 8206358809489724725, 15710959248597008897, 7891602991951624915, 13522388770433915878, 13885329677457736606, 5437216125826981154, 5828187362897965181, 1826814258047946771, 101076847761330219, 13722996303463886065, 8903413737919218637, 10036164134225207667, 10110544340826414078, 11616405843100478553, 11290966342014554162, 3279405133651105250, 18129332858809600283, 3842465837554359418, 6716889316224152410, 13315990744358110323, 8582117804084448577, 7011339168466747000]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xorshift1024 = Rand::rand(&mut sm); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); } #[test] fn test_xoroshiro128_sm64_seed_jumps() { let seed: u64 = 1477780685585184119; let t_vals: Vec = vec![7363123556067731325, 11743806326703499081, 11017078471850861282, 6537481313430306491, 1734032112987717604, 5180571021312121954, 3442966274224547762, 4094090387771775361, 18054519279123885422, 14557847324980967237, 6042207721959556892, 16758864894686705829, 11096095272679097818, 880786699494201485, 15328614793127720471, 13892737921325360346, 8325147650871463291, 3991156015381259310, 18068907175194483049, 15416978590692154546, 6957056196276506653, 15485008903412937461, 13150412147600451329, 6145842285392582846, 16515019917555447020, 256586483171449133, 2718459902581448649, 7091617294121361198, 15206544481892958765, 1270439699417559690, 1319940446266325114, 6237439622392080613, 5207717649918826118, 84863475645399540, 1345811548000146967, 14567228697863434988, 8287116353595203179, 2107959157140947859, 12171276951494883762, 9800690783379362250, 5826182796358441966, 351365107720279578, 3763752402021015792, 4377946622975149565, 17065932569806129746, 2246497116407309970, 5850190023311132789, 13588387146044389660, 8821738610530612520, 5335768027764772758]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xoroshiro128 = Rand::rand(&mut sm); rng.jump(10); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); } #[test] fn test_xorshift128_sm64_seed_jumps() { let seed: u64 = 1477780566345517426; let t_vals: Vec = vec![2898780227817592423, 10564003588519681288, 706169223508926661, 1726443879602479250, 9041239627918582700, 10042685306192430429, 15768972254883352514, 13263823228969469744, 17926358763063352546, 13485994777585816850, 559214318267761349, 13313816255709747081, 17524698450055253856, 7845726734300964129, 5267282915185541245, 7971132292829859275, 3331933060917754104, 10421958752966785644, 11828376425040553548, 7326508797291016532, 11233478458425605513, 14078266831421792009, 10110661748467841769, 3996513174299922950, 10764203498239380000, 11769497334896944465, 1578817649812051582, 12929521433805796527, 15209031551089675233, 9523182755265117704, 16359629716668803956, 9411167641273213463, 7151370879523844722, 11142304699119152166, 3523804126707148015, 2986061397992491393, 10445655305803481495, 16523509630980497064, 9784407109778557434, 8528249408899799560, 11984302998692256168, 3114038835576107181, 10003252390839736535, 9635779149713501666, 9361642498977356313, 109383826312025047, 6573228195939632801, 6348339904240198135, 12688408626692700841, 1374630186161923550]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xorshift128 = Rand::rand(&mut sm); rng.jump(10); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); } #[test] fn test_xorshift1024_sm64_seed_jumps() { let seed: u64 = 1477780352127933297; let t_vals: Vec = vec![17641988979641603474, 4847548182235977104, 17137928101850435504, 4842480085416740988, 13172406546208354925, 13101965437943000717, 16588559302924825448, 14136610242086978942, 7111662841222420609, 9009248264141451009, 14350130973774676344, 2903269128173847592, 11456652620197842681, 14026681682938136654, 17225824107635646499, 17816440587602666832, 11006456248319870885, 10239434151017996415, 4452514510721243157, 2266999289835825184, 12824011692338984914, 16011958552421346244, 9828552592983939148, 6484325738934960683, 2164862324844719879, 9281647739458560697, 1335525705301323595, 12206882149301317038, 2517682921753729831, 15501501099127606764, 15065197524490801724, 4043690309651605218, 12565795083143911598, 17615628902989541138, 15924637082729135978, 17923079888512491966, 3924685391800452966, 11341097787088360407, 3565215538960722114, 10612533478339550159, 4042832868931920712, 9392072675245242469, 10774252430134360305, 6229194964116808556, 7190764606554748082, 17799074144192675038, 2440282438332276260, 3831136930614945258, 7073407240019580288, 544911792544382917]; let mut sm: SplitMix64 = SeedableRng::from_seed(seed); let mut rng: Xorshift1024 = Rand::rand(&mut sm); rng.jump(10); let vals = rng.gen_iter::().take(t_vals.len()).collect::>(); assert!(iter_eq(t_vals, vals)); }