-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-temp-files-of-random-int64s.linq
53 lines (42 loc) · 1.36 KB
/
generate-temp-files-of-random-int64s.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Query Kind="Program">
<Namespace>System.CodeDom.Compiler</Namespace>
</Query>
void Main()
{
const string ns1filename = "c:/temp/ns1.stream";
const string ns2filename = "c:/temp/ns2.stream";
using(TempFileCollection tfc = new TempFileCollection())
{
Random rand = new Random();
//byte[] buffer;
tfc.AddFile(ns1filename, false);
tfc.AddFile(ns2filename, false);
using FileStream fs1 = File.Open(ns1filename, FileMode.CreateNew);
BinaryWriter bw1 = new BinaryWriter(fs1);
using FileStream fs2 = File.Open(ns2filename, FileMode.CreateNew);
BinaryWriter bw2 = new BinaryWriter(fs2);
byte[] int64Buffer = new byte[8];
for (int i = 0; i < 1000000000; i++)
{
rand.NextBytes(int64Buffer);
//a.Dump();
long rv = BitConverter.ToInt64(int64Buffer, 0);
bw1.Write(rv);
//Console.WriteLine("{0}", rv);
rand.NextBytes(int64Buffer);
//a.Dump();
rv = BitConverter.ToInt64(int64Buffer, 0);
//Console.WriteLine("{0}", rv);
bw2.Write(rv);
}
fs1.Position = 0;
using BinaryReader br1 = new BinaryReader(fs1);
fs2.Position = 0;
using BinaryReader br2 = new BinaryReader(fs2);
int64Buffer = br1.ReadBytes(8);
Console.WriteLine(BitConverter.ToInt64(int64Buffer, 0));
int64Buffer = br2.ReadBytes(8);
Console.WriteLine(BitConverter.ToInt64(int64Buffer, 0));
}
}
// You can define other methods, fields, classes and namespaces here