private static Int64 NextInt64(Random rnd)
{
var buffer = new byte[sizeof(Int64)];
rnd.NextBytes(buffer);
return BitConverter.ToInt64(buffer, 0);
}
above method is from this thread: Generate random values in C#
It will be used in an abstract event class to generate unique eventId. that class will be used frequently because we need to send lots of event. When I call above method in the event class constructor which option is better from the performance and unique value point of view:
- create a
Random
object withnew
and pass it into above method each time; - create a static
Random
object at very beginning and use it to call above method repeatedly when needed.