MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / shuffle_flags

Function shuffle_flags

src/display.rs:225–247  ·  view source on GitHub ↗

Print the top title row: version (left) + country flags (right). Returns a shuffled copy of `flags` using xorshift64 seeded from time + PID. Avoids pulling in `rand` for what is purely a cosmetic per-render shuffle.

(flags: &[String])

Source from the content-addressed store, hash-verified

223///
224/// Avoids pulling in `rand` for what is purely a cosmetic per-render shuffle.
225fn shuffle_flags(flags: &[String]) -> Vec<String> {
226 use std::time::{SystemTime, UNIX_EPOCH};
227 let mut out = flags.to_vec();
228 if out.len() < 2 {
229 return out;
230 }
231 let mut state: u64 = SystemTime::now()
232 .duration_since(UNIX_EPOCH)
233 .map_or(0xdead_beef_cafe_babe, |d| d.as_nanos() as u64)
234 .wrapping_add(u64::from(std::process::id()));
235 if state == 0 {
236 state = 0xdead_beef_cafe_babe;
237 }
238 for i in (1..out.len()).rev() {
239 // xorshift64
240 state ^= state << 13;
241 state ^= state >> 7;
242 state ^= state << 17;
243 let j = (state % (i as u64 + 1)) as usize;
244 out.swap(i, j);
245 }
246 out
247}
248
249fn print_version_flags_row(country_flags: &[String], inner_width: usize) {
250 let version = env!("CARGO_PKG_VERSION");

Callers 1

print_version_flags_rowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected