Skip to content

Commit

Permalink
Add API compatible random* functions to lookup.js
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim committed Nov 6, 2019
1 parent de2b5d3 commit 829d46d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@

import { isValidArrangement, isValidID } from './helpers.js'

/**
* Returns a random starting position, with its ID and arrangement.
*
* @returns {Object} An object with the starting position's ID and arrangement
*/
export function random() {
const id = randomID()
const arrangement = decode(id)
return { id, arrangement }
}

/**
* Picks a random starting position's ID.
*
* @returns {number} The starting position's ID
*/
export function randomID() {
return Math.floor(Math.random() * 960)
}

/**
* Given an ID, returns the starting position's arrangement of pieces.
*
Expand Down

0 comments on commit 829d46d

Please sign in to comment.