Module: GenerateData

Utilities for generating (random) data for benchmarking and exploring data.
Parameters:
Name Type Description
exports Object this is the object which will recieve the exports of this file
Source:
Tutorials:
  • Tutorial: test/javascript/generate-data-spec.js

Extends

  • AnyObject

Methods

(static) createArrayOfRandomIntegers(n, start, end) → {Array}

Create an array of random numbers can be used to create data which can be reused later for debugging sorting algorithms and improving the runtime of your data crunching.

If you want to have unique integers, see createArrayOfRandomUniqueIntegers below.

Parameters:
Name Type Description
n int The size of the array to be creatd
start int An optional minimal value, otherwise assumed to be 0
end int An optional maximal value, otherwise assumed to be n
Source:
Returns:
An array of random unique integers
Type
Array

(static) createArrayOfRandomUniqueIntegers(n, start, end) → {Array}

Create an array of random unique numbers can be used to create data which can be reused later for debugging sorting algorithms and improving the runtime of your data crunching.
Parameters:
Name Type Description
n int The size of the array to be creatd
start int An optional minimal value, otherwise assumed to be 0
end int An optional maximal value, otherwise assumed to be n
Source:
Returns:
An array of random unique integers
Type
Array

(static) shuffle(shuffleMe) → {this}

Fisher–Yates shuffling is similar to randomly picking numbered tickets (combinatorics: distinguishable objects) out of a hat without replacement until there are none left.

It was reduced to run in linear O(n) time by Durstenfeld 1964 by looping through the array just once O(n) and at each index, finding a random other index in the array to swap places with.

    Pseudocode
    for i from n − 1 downto 1 do
       j ← random integer with 0 ≤ j ≤ i
       exchange a[j] and a[i]
    
Parameters:
Name Type Description
shuffleMe Array An array to be shuffled
Source:
Returns:
This, for chaining other operations.
Type
this

(static) sortRandomUniqueIntegers(sortMe, minValue, maxValue) → {Array}

This is an interesting approach to a unique problem. If you need to sort a dense set of random integers who are only unique (or you don't mind if you only get unique one back) then you can think of the integers not as an array of integers, but more like a bitmap where 0 if the integer is not present, and 1 if it is present.

In this way the datastruture causes the data to be sorted. What is interesting with this approach is that it shows how a datastructure can be leveraged to reduce runtime.

References: Bently 1986

Parameters:
Name Type Description
sortMe Array An array of random integers
minValue int An optional smallest value in the input array, otherwise assumed to be 0
maxValue int An optional largest value in the input array, otherwise assumed to be the size of sortMe
Source:
Returns:
A sorted array of unique integers which were in sortMe
Type
Array