N/crypto/random Module: Secure Random Data Generation
The N/crypto/random module provides methods for generating secure random bytes, integers, and UUIDs in SuiteScript applications.
The N/crypto/random module enables developers to generate secure random data needed for various applications within NetSuite. This module is available for both client and server scripts, making it versatile for different scripting needs.
What Methods Are Available in the N/crypto/random Module?
The N/crypto/random module includes the following primary methods:
random.generateBytes(options)
- Return Type:
Uint8Array - Description: Generates a cryptographically strong pseudorandom set of bytes.
- Parameters:
Parameter Type Required / Optional Description options.sizenumber Required The number of bytes to generate; between 1 and 512.
Code Sample:
// Generate 5 random bytes of datavar bytes = random.generateBytes({size: 5});random.generateInt(options)
- Return Type:
number - Description: Generates a cryptographically strong pseudorandom number.
- Parameters:
Parameter Type Required / Optional Description options.maxnumber Required End of random range (exclusive). options.minnumber Optional Start of random range; default is 0.
Code Sample:
// Generate a random number between 0 and 100 (excluded)var number = random.generateInt({max: 100});// Generate a random number between 10 and 100 (excluded)var anotherNumber = random.generateInt({min: 10, max: 100});random.generateUUID()
- Return Type:
string - Description: Generates a v4 Universally Unique Identifier (UUID) using a secure random number generator.
Who This Affects
This module is particularly useful for:
- Developers creating custom scripts that require secure random data.
- Administrators managing security protocols that depend on unique identifiers or random data generation.
Key Takeaways
- The N/crypto/random module provides essential functions for secure random data generation.
- Available for both client and server scripts, enhancing flexibility.
- Critical for applications requiring unique identifiers or secure pseudorandom numbers.
Frequently Asked Questions (4)
Do I need to enable a feature flag to use the N/crypto/random module?
How many bytes can I generate using the random.generateBytes method?
Can random.generateInt generate both positive and negative numbers?
Is the random.generateUUID method suitable for client scripts?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
