Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a GUID in R?

Tags:

guid

uuid

random

r

How can I generate GUIDs and UUIDs in R?

I would like to be able to generate GUIDs based on the hardware etc. of the machine running the rsession.

As a fallback, however, I would be happy to create UUIDs that comply with rfc4122.

Is there a package that can create GUIDs? Otherwise, does someone have some RFC4122 compatible UUID code lying about?

like image 986
fmark Avatar asked May 08 '12 05:05

fmark


People also ask

How do I generate a new GUID?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

What is UUID generator?

A UUID (Universal Unique Identifier) is a 128-bit value used to uniquely identify an object or entity on the internet. Depending on the specific mechanisms used, a UUID is either guaranteed to be different or is, at least, extremely likely to be different from any other UUID generated until A.D. 3400.

Will GUID ever run out?

Absolutely. Even if only one GUID is generated per second, we'll run out in a scant 9 quintillion years. That's well before the heat death of the Universe.


2 Answers

The optimal choice for this now is the uuid package. It consists of one function (UUIDgenerate) that doesn't rely on R's internal random number generators and so doesn't suffer any consequences from using set.seed in a session as @thelatemail's answer does. You can choose to have the UUID be generated either by the package's internal random number generator or based on time.

like image 82
stanekam Avatar answered Sep 21 '22 13:09

stanekam


If you are using R in Unix environment, you can get UUID in R using system() command.

On Linux (Ubuntu 12.04 LTS):

my_uuid <- system("uuid",intern=T) my_uuid [1] 0f62f1de-418d-11e3-8a19-cb0ceccb58ec 

On Mac OS X 10.8:

my_uuid <- system("uuidgen", intern=T) my_uuid [1] 9A9D64DF-EB01-47E7-B16E-DC0343951883 

Far as I know, both uuid and uuidgen follows UUID Version 4 format.

like image 36
Samir Avatar answered Sep 22 '22 13:09

Samir