I want to create random unique numbers (UUIDs) as the following


First I tried this

$ rndnum=` echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM"-"echo $RANDOM`

$ echo $rndnum
30380-echo 21875-echo 14791-echo 32193-echo 11503

What is the right way to create the following (where f is any number)?

  • 5
    Random numbers are not necessarily unique. – JdeBP Feb 14 '19 at 9:39
  • yes , seems , this number is from presto configuration ( prestodb.github.io/docs/current/installation/deployment.html ) – yael Feb 14 '19 at 9:41
  • 10
    Note that UUIDs are not just random numbers stringed together. – Kusalananda Feb 14 '19 at 9:44
  • 9
    I've spent too many hours debugging scripts which assume "unlikely" is the same as "won't happen". If this is supposed to be a UUID then please do use an actual UUID, there are strict constraints on the way they are generated. If you could elaborate the reason you need this we might be able to help more. – Philip Couling Feb 14 '19 at 9:51

On Linux, the util-linux/util-linux-ng package offers a command to generate UUIDs: uuidgen.

$ uuidgen

To quote the manual:

The uuidgen program creates (and prints) a new universally unique identifier (UUID) using the libuuid(3) library. The new UUID can reasonably be considered unique among all UUIDs created on the local system, and among UUIDs created on other systems in the past and in the future.

There are two types of UUIDs which uuidgen can generate: time-based UUIDs and random-based UUIDs. By default uuidgen will generate a random-based UUID if a high-quality random number generator is present. Otherwise, it will choose a time-based UUID. It is possible to force the generation of one of these two UUID types by using the -r or -t options.

Addendum: The OP had provided a link in the comments to the documentation for Presto DB. After a bit of searching, I found this related discussion where it is explicitly mentioned that the node.id property is indeed a UUID.

Adding the information provided by frostschutz in a comment:

As an alternative to the uuidgen/libuuid approach, you can make use of an interface exposed by the Linux kernel itself to generate UUIDs:

$ cat /proc/sys/kernel/random/uuid

The UUID is re-generated on each request.

  • 2
    The final touch would be printf 'node.id=%s\n' "$( uuidgen )" – Kusalananda Feb 14 '19 at 10:28
  • well done , this is very good answer – yael Feb 14 '19 at 10:55
  • 19
    possible fallback if uuidgen is unavailable: cat /proc/sys/kernel/random/uuid – frostschutz Feb 14 '19 at 10:59
  • 2
    @frostschutz that's much better -- that should've been the answer – mosvy Feb 14 '19 at 13:05
  • @frostschutz I have added the information on this kernel interface to my answer. Thank you. – Haxiel Feb 14 '19 at 13:32

On a raspberry PI, and probably others, the command is simply:


It should be preinstalled, but if not, this should do it: sudo apt install uuid

  • I think you perhaps mean Raspberry PI OS (AKA Raspbian). Remember that a Raspberry Pi can run many different operating systems. – Philip Couling Dec 18 '20 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.