39 lines
815 B
C
39 lines
815 B
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
|
|
uint32_t xorshift32(uint32_t x)
|
|
{
|
|
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
|
|
x = x ^ (x << 13);
|
|
x = x ^ (x >> 17);
|
|
x = x ^ (x << 5);
|
|
return x;
|
|
}
|
|
|
|
uint32_t get_rand(uint32_t x) {
|
|
uint32_t out = 0;
|
|
int i;
|
|
for (i = 0; i < 32; i++) {
|
|
x = xorshift32(x);
|
|
if ((x & 1) == 1)
|
|
out = out | (1<< i);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
int i;
|
|
|
|
int fd = open("rom.bin", O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
|
uint32_t init = 1;
|
|
for (i = 0; i < 2048; i++) {
|
|
init = get_rand(init);
|
|
// printf("%08x\n", init);
|
|
write(fd, &init, sizeof(init));
|
|
}
|
|
|
|
return 0;
|
|
} |