-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnique IDs.linq
30 lines (25 loc) · 952 Bytes
/
Unique IDs.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
<Query Kind="Statements">
<NuGetReference>MathNet.Numerics</NuGetReference>
<Namespace>MathNet.Numerics.Distributions</Namespace>
<Namespace>MathNet.Numerics.Random</Namespace>
</Query>
string id;
//dt.Dump();
// random byte id in hex
Console.WriteLine("random byte id in hex");
System.Random rng = SystemRandomSource.Default;
byte[] byteArray = rng.NextBytes(8);
id = BitConverter.ToString(byteArray).Replace("-", string.Empty);
id.Dump();
Console.WriteLine();
// date time id. will have collisions if events happen at same time
Console.WriteLine("date time id. will have collisions if events happen at same time");
var dt = DateTime.Now;
id = dt.ToString("yyyyMMddHHmmss");
id.Dump();
Console.WriteLine();
// make id unique but sortable by prepending date time
Console.WriteLine();
Console.WriteLine("make id unique but sortable by prepending date time");
id += "_" + BitConverter.ToString(byteArray).Replace("-", string.Empty);
id.Dump();