Extend badrand with badrand_buf
This commit is contained in:
parent
6c3d50b6a5
commit
0dbb13fea0
2 changed files with 23 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#include "badrand.h"
|
#include "badrand.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define PRAND_BUILD_SEED \
|
#define PRAND_BUILD_SEED \
|
||||||
((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * (uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \
|
((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * (uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \
|
||||||
|
|
@ -24,7 +25,23 @@ uint64_t badrand_range(uint64_t min, uint64_t max) {
|
||||||
return min + (x % range);
|
return min + (x % range);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbadprand(uint64_t s) {
|
void badrand_buf(char *buf, size_t len) {
|
||||||
|
unsigned char *p = (unsigned char *)buf;
|
||||||
|
|
||||||
|
while (len >= 8) {
|
||||||
|
uint64_t r = badrand();
|
||||||
|
memcpy(p, &r, 8);
|
||||||
|
p += 8;
|
||||||
|
len -= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > 0) {
|
||||||
|
uint64_t r = badrand();
|
||||||
|
memcpy(p, &r, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbadrand(uint64_t s) {
|
||||||
if (s) {
|
if (s) {
|
||||||
seed ^= (s * 0x9e3779b97f4a7c15ULL) + (seed << 6) + (seed >> 2);
|
seed ^= (s * 0x9e3779b97f4a7c15ULL) + (seed << 6) + (seed >> 2);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,9 @@ uint64_t badrand();
|
||||||
*/
|
*/
|
||||||
uint64_t badrand_range(uint64_t min, uint64_t max);
|
uint64_t badrand_range(uint64_t min, uint64_t max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fills buffer with random data
|
||||||
|
*/
|
||||||
|
void badrand_buf(char *buf, size_t len);
|
||||||
|
|
||||||
#endif // BADRAND_H
|
#endif // BADRAND_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue