Is there a way to generate a random UUID, which consists only of numbers?

后端 未结 10 1547
一生所求
一生所求 2020-12-09 09:27

Java\'s UUID class generates a random UUID. But this consists of letters and numbers. For some applications we need only numbers. Is there a way to generate random UUID that

10条回答
  •  无人及你
    2020-12-09 09:39

    Random is not universally unique. If you want to use UUIDs as opposed to the Random class as suggested by others, you could simply use a regex to strip out everything except numerics from the UUID. Try something like this,

    String id = UUID.randomUUID().toString().replaceAll("[^0-9]", "");

提交回复
热议问题