Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use rand::Rng;
- use rand::distributions::Distribution;
- use rand::seq::SliceRandom;
- const ZIP_CODES: &[&str] = &[
- "79936",
- "90011",
- "60629",
- "90650",
- "90201",
- "77084",
- "92335",
- "78521",
- "77449",
- "78572",
- "90250",
- "90280",
- "11226",
- "90805",
- "91331",
- "08701",
- "90044",
- "92336",
- "00926",
- "94565",
- ];
- const MEANS: &[f64] = &[
- 242.53,
- 70.55,
- 153.54,
- 530.51,
- 756.82,
- 868.62,
- 342.91,
- 715.51,
- 118.13,
- 467.10,
- 266.31,
- 50.50,
- 976.94,
- 734.34,
- 873.61,
- 618.70,
- 12.98,
- 845.99,
- 168.96,
- 459.14,
- ];
- const CONVERSION_RATES: &[f64] = &[
- 0.76,
- 0.72,
- 0.78,
- 0.82,
- 0.85,
- 0.65,
- 0.88,
- 0.55,
- 0.20,
- 0.37,
- 0.86,
- 0.35,
- 0.94,
- 0.35,
- 0.79,
- 0.41,
- 0.53,
- 0.63,
- 0.87,
- 0.33,
- ];
- fn main() {
- let mut rng = rand::thread_rng();
- let mut samples = Vec::new();
- for (zip, (conversion_rate, mean)) in ZIP_CODES.iter().copied().zip(CONVERSION_RATES.iter().copied().zip(MEANS.iter().copied())) {
- let normal = rand::distributions::Normal::new(mean, 50.0);
- for _ in 0..rng.gen_range(50, 150) {
- if rng.gen_bool(conversion_rate) {
- samples.push(format!("('{}', {:.2}),", zip, normal.sample(&mut rng).max(0.0)));
- } else {
- samples.push(format!("('{}', 0.0),", zip));
- }
- }
- }
- samples.shuffle(&mut rng);
- eprintln!("INSERT INTO sessions (zip_code, sale_amount) VALUES");
- for sample in samples {
- eprintln!("{}", sample);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement