Generate a GUID

Problem

You want to create a new Globally Unique Identifier (GUID).

Solution

Use the shared System.Guid.NewGuid method.

Discussion

A GUID is a 128-bit integer. GUID values are tremendously useful in programming because they’re statistically unique. In other words, you can create GUID values continuously with little chance of every creating a duplicate. For that reason, GUIDs are commonly used to uniquely identify queued tasks, user sessions, and other dynamic information. They also have the advantage over random numbers or sequence numbers in the fact that they can’t easily be guessed. For example, if you write an XML Web service that assigns a new GUID to each user session, a malicious user won’t be able to determine what GUID a user ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.