| « Type systems and newspapers | Mass Effect and Fable 2 (and Kameo) » |
A one-off script deployed to a test machine, but still…
let rnd = System.Random()
let next _ = rnd.Next() |> char
let generate size = Seq.map next {0L .. size}
[<EntryPoint>]
let main args =
match args with
| [| size |] ->
generate (int64 size) |> Seq.iter System.Console.Write
0
| _ ->
printfn "Incorrect number of arguments"
1
It generates more than 4 GB of random characters. I wrote the parameter error checking out of habit, although it’s unnecessary in a one-off. The program as written is pretty slow, too, so I’m sure somebody reading this can suggest something faster.
Interestingly, the guy next to me wrote the same thing yesterday in Perl. His solution looked vaguely like:
open $file or die;
for($i = 0; $i < $ARGS[0]; $i++) {
print >>$file, "."
}
Except it was somehow longer than that…I think the file handling made it longer*. Excuse the massively incorrect Perl, I don’t remember it after 5 years of disuse. His version doesn’t generate random characters, but I think that would be easy to do in Perl. (probably char(rand()) or something?)
*I will post the code once I retrieve it from my IM history at work.