Skip to content

Instantly share code, notes, and snippets.

@goeblr
goeblr / DicomUID.cs
Created June 26, 2018 09:59 — forked from jaime-olivares/DicomUID.cs
Dicom UUID-derived UID generator
// A port from javascript: https://hcintegrations.ca/2014/05/14/quick-and-dirty-javascript-dicomweb-uid-generator/
public static string NewUID_dirty()
{
var r = new System.Random();
var uid = System.Text.RegularExpressions.Regex.Replace("2.25.xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx", "x", m => (r.Next()%16).ToString() );
return System.Text.RegularExpressions.Regex.Replace(uid, "y", m => (r.Next()&3|8).ToString());
}
// Trying to strictly follow the Dicom spec: ftp://medical.nema.org/medical/dicom/2013/output/html/part05.html#sect_B.2
// More details at: ISO/IEC 9834-8 / ITU-T X.667, Section 6.3