fn generate_random_file<P: AsRef<Path>>(&mut self, path: P) {
		let mode = (self.rng.next_u32() & 511) | 0o600;
		let len = match self.rng.gen_range(0, 100) {
			0 ..= 9 => 0, // Empty (10%)
			10 ..= 59 => self.rng.gen_range(1, 1024), // Small (50%)
			60 ..= 89 => self.rng.gen_range(1, 2*1024*1024), // Medium (30%)
			_ => self.rng.gen_range(1, 32*1024*1024), // Large (10%)
		};

		// Generate alphanumberic data sometimes
		let is_ascii = self.rng.gen_range(0, 2) == 0;

		{
			let file = fs::OpenOptions::new().write(true).create(true).mode(mode).open(path.as_ref()).unwrap();
			let mut writer = BufWriter::new(file);
			let mut written = 0;
			let mut buffer = [0u8; 4096];

			while written < len {
				let chunk_size = cmp::min(buffer.len(), len - written);

				if is_ascii {
					let string_data: String = (&mut self.rng).sample_iter(&rand::distributions::Alphanumeric).take(chunk_size).collect();
					writer.write_all(string_data.as_bytes()).unwrap();
					written += string_data.len();
				}
				else {
					self.rng.fill_bytes(&mut buffer);
					writer.write_all(&buffer[..chunk_size]).unwrap();
					written += chunk_size;
				}
			}
		}

		self.set_random_filetime(path);
	}
// Generate a random file at the given path.
// Length, contents, permissions, etc. will be random.
Generate a random file at the given path.
Length, contents, permissions, etc. will be random.
Generate a random file at the given path . Length contents permissions etc . will be random .
fn generate_random_file<P: AsRef<Path>>(&mut self, path: P) {
		let mode = (self.rng.next_u32() & 511) | 0o600;
		let len = match self.rng.gen_range(0, 100) {
			0 ..= 9 => 0, // Empty (10%)
			10 ..= 59 => self.rng.gen_range(1, 1024), // Small (50%)
			60 ..= 89 => self.rng.gen_range(1, 2*1024*1024), // Medium (30%)
			_ => self.rng.gen_range(1, 32*1024*1024), // Large (10%)
		};
		// Generate alphanumberic data sometimes
		let is_ascii = self.rng.gen_range(0, 2) == 0;
		{
			let file = fs::OpenOptions::new().write(true).create(true).mode(mode).open(path.as_ref()).unwrap();
			let mut writer = BufWriter::new(file);
			let mut written = 0;
			let mut buffer = [0u8; 4096];
			while written < len {
				let chunk_size = cmp::min(buffer.len(), len - written);
				if is_ascii {
					let string_data: String = (&mut self.rng).sample_iter(&rand::distributions::Alphanumeric).take(chunk_size).collect();
					writer.write_all(string_data.as_bytes()).unwrap();
					written += string_data.len();
				}
				else {
					self.rng.fill_bytes(&mut buffer);
					writer.write_all(&buffer[..chunk_size]).unwrap();
					written += chunk_size;
				}
			}
		}
		self.set_random_filetime(path);
	}
fn generate_random_file < P : AsRef < Path > > ( & mut self , path : P ) { let mode = ( self . rng . next_u32 ( ) & 511 ) | 0o600 ; let len = match self . rng . gen_range ( 0 , 100 ) { 0 ..= 9 => 0 , // Empty (10%) 10 ..= 59 => self . rng . gen_range ( 1 , 1024 ) , // Small (50%) 60 ..= 89 => self . rng . gen_range ( 1 , 2 * 1024 * 1024 ) , // Medium (30%) _ => self . rng . gen_range ( 1 , 32 * 1024 * 1024 ) , // Large (10%) } ; // Generate alphanumberic data sometimes let is_ascii = self . rng . gen_range ( 0 , 2 ) == 0 ; { let file = fs :: OpenOptions :: new ( ) . write ( true ) . create ( true ) . mode ( mode ) . open ( path . as_ref ( ) ) . unwrap ( ) ; let mut writer = BufWriter :: new ( file ) ; let mut written = 0 ; let mut buffer = [ 0u8 ; 4096 ] ; while written < len { let chunk_size = cmp :: min ( buffer . len ( ) , len - written ) ; if is_ascii { let string_data : String = ( & mut self . rng ) . sample_iter ( & rand :: distributions :: Alphanumeric ) . take ( chunk_size ) . collect ( ) ; writer . write_all ( string_data . as_bytes ( ) ) . unwrap ( ) ; written += string_data . len ( ) ; } else { self . rng . fill_bytes ( & mut buffer ) ; writer . write_all ( & buffer [ .. chunk_size ] ) . unwrap ( ) ; written += chunk_size ; } } } self . set_random_filetime ( path ) ; }
Generate a random file at the given path.
Generate a random file at the given path .
&mut self
path
P
&mut self
path
P