Skip to content

Instantly share code, notes, and snippets.

@joshua-stone
Last active April 30, 2022 17:57
Show Gist options
  • Save joshua-stone/576e5826302a720331a2686f25c957f1 to your computer and use it in GitHub Desktop.
Save joshua-stone/576e5826302a720331a2686f25c957f1 to your computer and use it in GitHub Desktop.
write_rand
[package]
name = "write_rand"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"
rand_xoshiro = "0.6.0"
[profile.release]
lto = true
extern crate rand;
extern crate rand_xoshiro;
use std::fs::File;
use std::io::Write;
use rand_xoshiro::Xoshiro256PlusPlus;
use rand_xoshiro::rand_core::{RngCore, SeedableRng};
const CHUNK_SIZE: i64 = 2_i64.pow(16);
const NUMBER: i64 = 0x100000000;
//const NUMBER: i64 = 0x400000000; // 4*2^32 copies are erroneous from md5sum, file length 17179869184
//const NUMBER: i64 = 0x200000000 // 2*2^32 copies are erroneous from md5sum, file length 8589934592
//const NUMBER: i64 = 0x100000001 // 2^32+1 copies without md5 detected error, file length 4294967297
//const NUMBER: i64 = 0x180000000 // copies without md5 detected error, file length 6442450944
//const NUMBER: i64 = 0x1FFFFFFFF
fn write_file(length: i64) {
let mut rng = Xoshiro256PlusPlus::from_entropy();
let mut file_ref = File::create("bigfile").expect("Create failed!");
let mut buf = vec![0u8; CHUNK_SIZE as usize].into_boxed_slice();
for _ in 0..(length / CHUNK_SIZE) {
rng.fill_bytes(buf.as_mut());
file_ref.write_all(&buf).expect("Write failed!");
}
}
fn main() {
write_file(NUMBER);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment