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.

·2 min read·View Oracle Docs

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:
    ParameterTypeRequired / OptionalDescription
    options.sizenumberRequiredThe number of bytes to generate; between 1 and 512.

Code Sample:

suitescript
// Generate 5 random bytes of data
var bytes = random.generateBytes({size: 5});

random.generateInt(options)

  • Return Type: number
  • Description: Generates a cryptographically strong pseudorandom number.
  • Parameters:
    ParameterTypeRequired / OptionalDescription
    options.maxnumberRequiredEnd of random range (exclusive).
    options.minnumberOptionalStart of random range; default is 0.

Code Sample:

suitescript
// 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.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Do I need to enable a feature flag to use the N/crypto/random module?
The article does not specify any need to enable a feature flag to use the N/crypto/random module. It appears to be available by default in SuiteScript applications.
How many bytes can I generate using the random.generateBytes method?
The random.generateBytes method can generate between 1 and 512 cryptographically strong pseudorandom bytes.
Can random.generateInt generate both positive and negative numbers?
Yes, the random.generateInt method can generate both positive and negative numbers based on the 'min' and 'max' parameters provided. If 'min' is set to a negative value, the range can include negative numbers.
Is the random.generateUUID method suitable for client scripts?
Yes, the random.generateUUID method is suitable for both client and server scripts, offering flexibility in different scripting environments within NetSuite.
Source: N/crypto/random Module Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →