Random Number Generator
Generate secure random numbers in any range.
crypto.getRandomValues()การใช้งานตัวเลขสุ่ม
Math.random() vs crypto.getRandomValues()
Math.random() ใช้อัลกอริทึมสุ่มเทียมแบบกำหนด seeded เมื่อเริ่มต้น สำหรับเกมและการจำลองส่วนใหญ่ถือว่าใช้ได้ แต่ crypto.getRandomValues() ดึงจาก entropy pool ของ OS ซึ่งเป็นแหล่งเดียวกันกับที่ใช้สำหรับการสร้างคีย์ cryptographic เครื่องมือนี้ใช้เวอร์ชันที่ปลอดภัยเสมอ
ครูที่จัดสลากในชั้นเรียนตั้ง min=1, max=30, count=1 เพื่อเลือกนักเรียนสุ่มโดยไม่มีอคติ นักพัฒนาที่เขียน unit test สร้าง random ID ที่ไม่ซ้ำกัน 100 รายการในช่วง 10000–99999 เพื่อ seed ฐานข้อมูลทดสอบ ผู้เล่น RPG บนโต๊ะจำลองการทอยลูกเต๋า 8 หน้าด้วยการตั้ง min=1, max=8 ทีมรักษาความปลอดภัยสร้าง PIN code สุ่มสำหรับข้อมูลประจำตัวการเข้าถึงครั้งเดียว
crypto.getRandomValues() เป็นส่วนหนึ่งของ Web Cryptography API ที่มีในเบราว์เซอร์ทุกรุ่นตั้งแต่ปี 2014 มันเติม typed array (Uint32Array ในเครื่องมือนี้) ด้วยไบต์ที่มาจาก entropy pool ของระบบปฏิบัติการ ต่างจาก Math.random() เอาต์พุตไม่สามารถคาดเดาได้จากการรู้เวลาหรือสถานะของเบราว์เซอร์ ทำให้เหมาะสำหรับการสร้าง PIN รหัสครั้งเดียว และความสุ่มที่ต้องทนต่อการโจมตีแบบเดา
เมื่อเปิดใช้งาน no-duplicates เครื่องมือจะสร้างช่วงจำนวนเต็มเต็ม สับเปลี่ยนโดยใช้อัลกอริทึม Fisher-Yates (แต่ละองค์ประกอบสลับกับดัชนีที่สุ่มแบบ cryptographic) จากนั้นนำ N องค์ประกอบแรก รับประกันการกระจายแบบสม่ำเสมอ ทุกการเรียงลำดับมีโอกาสเท่ากัน
- สลาก/ลุ้นรางวัล — การจับสลากสุ่มที่ยุติธรรมสำหรับของรางวัล
- การจำลองลูกเต๋า — เกมบนโต๊ะ การทดสอบความน่าจะเป็น
- การสุ่มตัวอย่าง — การเลือกรายการสุ่มจากรายการสำหรับการทดสอบ
- Seed รหัสผ่าน — การสร้าง PIN code สุ่มหรือ OTP
- การศึกษา — แบบฝึกหัดสถิติ การสาธิตความน่าจะเป็น
- เกม — การสับไพ่สุ่ม การมอบหมายทีม
คำถามที่พบบ่อย
- Is this truly random?
- This generator uses crypto.getRandomValues() — the browser's cryptographically secure pseudorandom number generator (CSPRNG). It is significantly more random than Math.random() and suitable for security-sensitive applications.
- What does 'no duplicates' do?
- When enabled, each number in the output appears only once — like drawing numbers from a hat without replacement. This uses a Fisher-Yates shuffle on the full range. Note: you cannot generate more unique numbers than there are integers in the range.
- What is the maximum number of values I can generate?
- You can generate up to 1,000 random numbers at once. For most use cases (lottery picks, random sampling, dice simulation) this is more than sufficient.
- How do I simulate a dice roll?
- Set Min to 1 and Max to 6 for a standard die. For multiple dice, increase the count. For a D20 (used in tabletop games), set Min to 1 and Max to 20.
- Can I use this for a lottery or raffle?
- Yes. Set Min to 1 and Max to your lottery range (e.g., 49 for UK Lotto), enable No Duplicates, and set count to the number of balls drawn (e.g., 6). This gives a fair random draw.
เครื่องมือที่เกี่ยวข้อง
- JSON Formatter, Validator & Repair Tool
Format, minify, validate, and repair JSON instantly in your browser. Sort keys alphabetically, auto-format on paste, download as file, escape/unescape strings — free, no sign-up, 100% client-side.
- ตัวสร้าง QR Code
สร้าง QR code สำหรับ URL ข้อความ Wi-Fi และอื่นๆ ดาวน์โหลดเป็น PNG
- ตัวสร้างรหัสผ่าน
สร้างรหัสผ่านสุ่มที่แข็งแกร่งด้วยความยาวและชุดอักขระที่กำหนดเอง
- Base64 เข้ารหัส / ถอดรหัส
เข้ารหัสข้อความเป็น Base64 หรือถอดรหัสกลับเป็นข้อความธรรมดา
- URL เข้ารหัส / ถอดรหัส
เข้ารหัสหรือถอดรหัส URL และ query strings ด้วย percent-encoding