# CSPRNG

> What is a CSPRNG, why is Math.random() unsafe for security tokens, and which APIs should you use instead?

Canonical: https://www.internhack.in/learn/interview/web-security/security-cryptographically-secure-random
Last updated: 2026-11-28

Difficulty: Advanced

## Question

What is a CSPRNG, why is Math.random() unsafe for security tokens, and which APIs should you use instead?

*The full answer is for InternHack members. Open the page link above to read it.*

## Concepts covered

CSPRNG, Entropy, Math.random, crypto.getRandomValues, Token Generation, Modulo Bias

Previous: [Brute Force Protection](https://www.internhack.in/learn/interview/web-security/security-brute-force-vulnerability) · Next: [Data at Rest](https://www.internhack.in/learn/interview/web-security/security-sensitive-data-rest) · [All of Web Security (OWASP, JWT, XSS, CSRF)](https://www.internhack.in/learn/interview/web-security)

## More Web Security (OWASP, JWT, XSS, CSRF) questions

- [Security Misconfiguration](https://www.internhack.in/learn/interview/web-security/security-security-misconfiguration)
- [Phishing Protection](https://www.internhack.in/learn/interview/web-security/security-phishing-prevention)
- [Social Engineering](https://www.internhack.in/learn/interview/web-security/security-social-engineering-basics)
- [Buffer Overflow](https://www.internhack.in/learn/interview/web-security/security-buffer-overflow-intro)
- [Blind SQL Injection](https://www.internhack.in/learn/interview/web-security/security-sql-blind-injection)
- [API Security](https://www.internhack.in/learn/interview/web-security/security-api-security-best-practices)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [Web Security (OWASP, JWT, XSS, CSRF)](https://www.internhack.in/learn/interview/web-security)
