N/crypto/random Module for Secure Random Data in SuiteScript
The N/crypto/random module offers methods for generating secure random data 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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category