| author | |
| committer | |
| log | 501b4aff9968e691283dd6ce637b503a12b03d38 |
| tree | 63eef0d033d39182a0f756a69e9791f618141dad |
| parent | a5cc5f7854b87f3daaff790deb6dec72b329f432 |
4 files changed, 111 insertions(+), 0 deletions(-)
lib/std/rand/Isaac64.zig+32| ... | @@ -208,3 +208,35 @@ test "isaac64 sequence" { | ... | @@ -208,3 +208,35 @@ test "isaac64 sequence" { |
| 208 | std.testing.expect(s == r.next()); | 208 | std.testing.expect(s == r.next()); |
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | |||
| 212 | test "isaac64 fill" { | ||
| 213 | var r = Isaac64.init(0); | ||
| 214 | |||
| 215 | // from reference implementation | ||
| 216 | const seq = [_]u64{ | ||
| 217 | 0xf67dfba498e4937c, | ||
| 218 | 0x84a5066a9204f380, | ||
| 219 | 0xfee34bd5f5514dbb, | ||
| 220 | 0x4d1664739b8f80d6, | ||
| 221 | 0x8607459ab52a14aa, | ||
| 222 | 0x0e78bc5a98529e49, | ||
| 223 | 0xfe5332822ad13777, | ||
| 224 | 0x556c27525e33d01a, | ||
| 225 | 0x08643ca615f3149f, | ||
| 226 | 0xd0771faf3cb04714, | ||
| 227 | 0x30e86f68a37b008d, | ||
| 228 | 0x3074ebc0488a3adf, | ||
| 229 | 0x270645ea7a2790bc, | ||
| 230 | 0x5601a0a8d3763c6a, | ||
| 231 | 0x2f83071f53f325dd, | ||
| 232 | 0xb9090f3d42d2d2ea, | ||
| 233 | }; | ||
| 234 | |||
| 235 | for (seq) |s| { | ||
| 236 | var buf0: [8]u8 = undefined; | ||
| 237 | var buf1: [7]u8 = undefined; | ||
| 238 | std.mem.writeIntLittle(u64, &buf0, s); | ||
| 239 | Isaac64.fill(&r.random, &buf1); | ||
| 240 | std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | ||
| 241 | } | ||
| 242 | } |
lib/std/rand/Pcg.zig+24| ... | @@ -99,3 +99,27 @@ test "pcg sequence" { | ... | @@ -99,3 +99,27 @@ test "pcg sequence" { |
| 99 | std.testing.expect(s == r.next()); | 99 | std.testing.expect(s == r.next()); |
| 100 | } | 100 | } |
| 101 | } | 101 | } |
| 102 | |||
| 103 | test "pcg fill" { | ||
| 104 | var r = Pcg.init(0); | ||
| 105 | const s0: u64 = 0x9394bf54ce5d79de; | ||
| 106 | const s1: u64 = 0x84e9c579ef59bbf7; | ||
| 107 | r.seedTwo(s0, s1); | ||
| 108 | |||
| 109 | const seq = [_]u32{ | ||
| 110 | 2881561918, | ||
| 111 | 3063928540, | ||
| 112 | 1199791034, | ||
| 113 | 2487695858, | ||
| 114 | 1479648952, | ||
| 115 | 3247963454, | ||
| 116 | }; | ||
| 117 | |||
| 118 | for (seq) |s| { | ||
| 119 | var buf0: [4]u8 = undefined; | ||
| 120 | var buf1: [3]u8 = undefined; | ||
| 121 | std.mem.writeIntLittle(u32, &buf0, s); | ||
| 122 | Pcg.fill(&r.random, &buf1); | ||
| 123 | std.testing.expect(std.mem.eql(u8, buf0[0..3], buf1[0..])); | ||
| 124 | } | ||
| 125 | } |
lib/std/rand/Sfc64.zig+32| ... | @@ -106,3 +106,35 @@ test "Sfc64 sequence" { | ... | @@ -106,3 +106,35 @@ test "Sfc64 sequence" { |
| 106 | std.testing.expectEqual(s, r.next()); | 106 | std.testing.expectEqual(s, r.next()); |
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | |||
| 110 | test "Sfc64 fill" { | ||
| 111 | // Unfortunately there does not seem to be an official test sequence. | ||
| 112 | var r = Sfc64.init(0); | ||
| 113 | |||
| 114 | const seq = [_]u64{ | ||
| 115 | 0x3acfa029e3cc6041, | ||
| 116 | 0xf5b6515bf2ee419c, | ||
| 117 | 0x1259635894a29b61, | ||
| 118 | 0xb6ae75395f8ebd6, | ||
| 119 | 0x225622285ce302e2, | ||
| 120 | 0x520d28611395cb21, | ||
| 121 | 0xdb909c818901599d, | ||
| 122 | 0x8ffd195365216f57, | ||
| 123 | 0xe8c4ad5e258ac04a, | ||
| 124 | 0x8f8ef2c89fdb63ca, | ||
| 125 | 0xf9865b01d98d8e2f, | ||
| 126 | 0x46555871a65d08ba, | ||
| 127 | 0x66868677c6298fcd, | ||
| 128 | 0x2ce15a7e6329f57d, | ||
| 129 | 0xb2f1833ca91ca79, | ||
| 130 | 0x4b0890ac9bf453ca, | ||
| 131 | }; | ||
| 132 | |||
| 133 | for (seq) |s| { | ||
| 134 | var buf0: [8]u8 = undefined; | ||
| 135 | var buf1: [7]u8 = undefined; | ||
| 136 | std.mem.writeIntLittle(u64, &buf0, s); | ||
| 137 | Sfc64.fill(&r.random, &buf1); | ||
| 138 | std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | ||
| 139 | } | ||
| 140 | } |
lib/std/rand/Xoroshiro128.zig+23| ... | @@ -131,3 +131,26 @@ test "xoroshiro sequence" { | ... | @@ -131,3 +131,26 @@ test "xoroshiro sequence" { |
| 131 | std.testing.expect(s == r.next()); | 131 | std.testing.expect(s == r.next()); |
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| 134 | |||
| 135 | test "xoroshiro fill" { | ||
| 136 | var r = Xoroshiro128.init(0); | ||
| 137 | r.s[0] = 0xaeecf86f7878dd75; | ||
| 138 | r.s[1] = 0x01cd153642e72622; | ||
| 139 | |||
| 140 | const seq = [_]u64{ | ||
| 141 | 0xb0ba0da5bb600397, | ||
| 142 | 0x18a08afde614dccc, | ||
| 143 | 0xa2635b956a31b929, | ||
| 144 | 0xabe633c971efa045, | ||
| 145 | 0x9ac19f9706ca3cac, | ||
| 146 | 0xf62b426578c1e3fb, | ||
| 147 | }; | ||
| 148 | |||
| 149 | for (seq) |s| { | ||
| 150 | var buf0: [8]u8 = undefined; | ||
| 151 | var buf1: [7]u8 = undefined; | ||
| 152 | std.mem.writeIntLittle(u64, &buf0, s); | ||
| 153 | Xoroshiro128.fill(&r.random, &buf1); | ||
| 154 | std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | ||
| 155 | } | ||
| 156 | } |