Library rand

Functions for generating random data

The strings generated here are not cryptographically secure, but they should be sufficient for most purposes.

Author:

  • Daniel Miller

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/rand.lua

Functions

charset (left_bound, right_bound, charset)

Generate a charset that can be passed to random_string

random_alpha (len)

Generate a random alpha word

random_string (len, charset)

Generate a random string.

Functions

charset (left_bound, right_bound, charset)

Generate a charset that can be passed to random_string

Parameters

left_bound
The lower bound character or byte value of the set
right_bound
The upper bound character or byte value of the set
charset
Optional, a charset table to augment. By default a new charset is created.

Return value:

A charset table
random_alpha (len)

Generate a random alpha word

Convenience wrapper around random_string to generate a random string of lowercase alphabetic characters.

Parameters

len
The length of word to return

Return value:

A string of random characters between 'a' and 'z' inclusive.
random_string (len, charset)

Generate a random string.

You can either provide your own charset or the function will generate random bytes, which may include null bytes.

Parameters

len
Length of the string we want to generate.
charset
Charset that will be used to generate the string. String or table

Return value:

A random string of length len consisting of characters from charset if one was provided, or random bytes otherwise.