1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00
CLK/Machines/Utility/MemoryFuzzer.cpp

29 lines
617 B
C++
Raw Normal View History

//
// MemoryFuzzer.cpp
// Clock Signal
//
// Created by Thomas Harte on 19/10/2016.
// Copyright 2016 Thomas Harte. All rights reserved.
//
#include "MemoryFuzzer.hpp"
#include <cstdlib>
void Memory::Fuzz(uint8_t *buffer, std::size_t size) {
2020-05-10 03:03:33 +00:00
const unsigned int divider = (unsigned(RAND_MAX) + 1) / 256;
unsigned int shift = 1, value = 1;
2017-03-26 18:34:47 +00:00
while(value < divider) {
value <<= 1;
2020-05-10 03:03:33 +00:00
++shift;
}
2020-05-10 03:03:33 +00:00
for(size_t c = 0; c < size; c++) {
buffer[c] = uint8_t(std::rand() >> shift);
}
}
void Memory::Fuzz(uint16_t *buffer, std::size_t size) {
Fuzz(reinterpret_cast<uint8_t *>(buffer), size * sizeof(uint16_t));
}