📜  红宝石 |随机 uuid()函数

📅  最后修改于: 2022-05-13 01:55:33.649000             🧑  作者: Mango

红宝石 |随机 uuid()函数

Random#uuid() : uuid()是一个 Random 类方法,它检查返回一个随机的 v4 UUID(通用唯一标识符)。

示例 #1:

# Ruby code for Random.uuid() method
  
# loading library
require 'securerandom'
  
# declaring Random value
date_a = SecureRandom.uuid
  
# declaring Random value
date_b = SecureRandom.uuid
  
# uuid value
puts "Random uuid form : #{date_a}\n\n"
  
puts "Random uuid form : #{date_b}\n\n"

输出 :

Random uuid form : 219474f0-60c5-43b4-8e7f-f91b5c5e1f38

Random uuid form : d6800817-c27b-4651-8d98-dc12eec46706

示例 #2:

# Ruby code for Random.uuid() method
  
# loading library
require 'securerandom'
  
# declaring Random value
date_a = SecureRandom.uuid
  
# declaring Random value
date_b = SecureRandom.uuid
  
# uuid value
puts "Random uuid form : #{date_a}\n\n"
  
puts "Random uuid form : #{date_b}\n\n"

输出 :

Random uuid form : f74b43f6-8b9c-4cd1-aff2-177f517b77aa

Random uuid form : baba4612-6931-46a0-aa8b-7a105fd2f194