Skip to content

Commit 861328e

Browse files
committed
fix XorShift128+ / Xoshiro256** seed by string
1 parent fdf1cf4 commit 861328e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ext/random/random.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,9 @@ PHP_METHOD(Random_Engine_XorShift128Plus, __construct)
14201420
if (str_seed->len == 16) {
14211421
/* Endianness safe copy */
14221422
for (i = 0; i < 2; i++) {
1423+
state->s[i] = 0;
14231424
for (j = 0; j < 8; j++) {
1424-
state->s[i] += (unsigned char) ZSTR_VAL(str_seed)[(i * j) + j] >> (j * 8);
1425+
state->s[i] += ((uint64_t) (unsigned char) ZSTR_VAL(str_seed)[(i * 8) + j]) << (j * 8);
14251426
}
14261427
}
14271428
} else {
@@ -1452,8 +1453,9 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
14521453
if (str_seed->len == 32) {
14531454
/* Endianness safe copy */
14541455
for (i = 0; i < 4; i++) {
1456+
state->s[i] = 0;
14551457
for (j = 0; j < 8; j++) {
1456-
state->s[i] += (unsigned char) ZSTR_VAL(str_seed)[(i * j) + j] >> (j * 8);
1458+
state->s[i] += ((uint64_t) (unsigned char) ZSTR_VAL(str_seed)[(i * 8) + j]) << (j * 8);
14571459
}
14581460
}
14591461
} else {

0 commit comments

Comments
 (0)