let random_char chars = let index = Random.int (String.length chars) in String.get chars index let generate_password length use_special use_digits use_upper use_lower = let chars = (if use_special then "!@#$%^&*()" else "") ^ (if use_digits then "0123456789" else "") ^ (if use_upper then "ABCDEFGHIJKLMNOPQRSTUVWXYZ" else "") ^ (if use_lower then "abcdefghijklmnopqrstuvwxyz" else "") in String.init length (fun _ -> random_char chars) let () = Random.self_init (); print_string "Enter password length: "; let length = read_int () in print_string "Include special characters? (y/n): "; let use_special = read_line () = "y" in print_string "Include digits? (y/n): "; let use_digits = read_line () = "y" in print_string "Include uppercase letters? (y/n): "; let use_upper = read_line () = "y" in print_string "Include lowercase letters? (y/n): "; let use_lower = read_line () = "y" in let password = generate_password length use_special use_digits use_upper use_lower in Printf.printf "Generated password: %s\n" password