ファイルにデータ(Seq系)を保存したい
で作成した乱数などを保存したい場合のお話。以下のコードでOKだった。
using (System.IO.File.CreateText("test.txt")) (fun file -> Normal.Samples(new MersenneTwister(), 1.0, 3.0) |> Seq.take 100 |> Seq.iter file.WriteLine)
System.Environment.CurrentDirectory
で取得出来るカレントディレクトリにtest.txtが作成されていて、結果が保存される。
〜追記〜
あるいは、コメント欄でいげ太さんにアドバイスいただいたように
let x = seq{1..10} |> Seq.map (fun x -> x.ToString()) |> Seq.toArray File.WriteAllLines("hoge.txt", x)
でもいい。ありがとうございます!