Random#uuid():uuid()是一種隨機類方法,該方法檢查返回的是隨機v4 UUID(通用唯一IDentifier)。
用法:Random.uuid()
參數:隨機值
返回:隨機v4 UUID(通用唯一IDentifier)。
示例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
相關用法
- Ruby Random new()用法及代碼示例
- Scala Random ==()用法及代碼示例
- Ruby Random hex()用法及代碼示例
- Ruby Random srand()用法及代碼示例
- Ruby Random new_seed()用法及代碼示例
- Ruby Random rand()用法及代碼示例
- Ruby Random random_bytes()用法及代碼示例
- Ruby Random random_number()用法及代碼示例
- Ruby Random seed()用法及代碼示例
- Ruby Random base64()用法及代碼示例
- Ruby Random urlsafe_base64()用法及代碼示例
- Ruby Random bytes()用法及代碼示例
- Ruby Set add?用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Random uuid() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。