C # uses a GUID class to generate non-repeating random numbers

Source: Internet
Author: User

What is a GUID

GUID (Globally unique identifier)
The globally unique identifier (guid,globally unique Identifier) is a numeric identifier generated by the algorithm with a binary length of 128 bits. GUIDs are primarily used in networks or systems that have multiple nodes, multiple computers. Ideally, no computer or computer cluster will generate two identical GUIDs. The total number of GUIDs reaches 2^128 (3.4x10^38), so the probability of randomly generating two identical GUIDs is very small, but not 0. The term GUID also sometimes refers to Microsoft's implementation of the UUID standard. Ideally, no computer or computer cluster will generate two identical GUIDs. The probability of randomly generating two identical GUIDs is very small, but not 0. Therefore, the algorithm used to generate the GUID usually adds non-random parameters (such as time) to ensure that this repetition does not occur. On the Windows platform, GUIDs are widely used in Microsoft products to identify objects such as registry keys, class and interface identities, databases, system catalogs, and so on.formatThe format of the GUID is "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", where each x is a 4-bit hexadecimal number in the range of 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid GUID value.GUID features★ When a GUID is required, it can be generated automatically by the algorithm and does not require an authoritative authority to manage it. ★guid can theoretically produce the world's only value, which is convenient for future data import.GUID controversyThe potential drawbacks of the GUID values have aroused the concern of the privacy advocates. In March 1999, the U.S. Federal Commerce Commission was asked to investigate Microsoft's use of GUID values. The controversy primarily involves the use of GUID values for Office 97 and Office 2000 documents. An Office document, such as a Word file or an Excel spreadsheet, uses a GUID value that is not visible to the user. However, there are many reports that the author of the document can be traced by a trace of the GUID value, even if the author has taken a special approach, they can be traced. In response to these questions, Microsoft has released an Office 97 patch SR2, which prohibits the use of the GUID feature and can also remove the GUID of an existing document. The potential for misuse of Intel processor serial numbers is essentially the same as the problem with the above GUID values.

C # uses a GUID class to generate random numbers

         Public  Static intGetRandomNumber (intMinintmax) {            intRTN =0; Random R=NewRandom (); byte[] buffer =Guid.NewGuid ().            Tobytearray (); intISeed = bitconverter.toint32 (buffer,0); R=NewRandom (iSeed); RTN= R.next (min, Max +1); returnRtn; }

Java

Importpublicclass/** @param*/  publicstaticvoid//UUID uuid =  Uuid.randomuuid (); System.out.println (". {"+uuid.tostring () +"} "

C # uses a GUID class to generate non-repeating random numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.