// Return a random sample of values over a set of bounds with
// a specified quantity.

var rand = require('./rand')
var randInt = require('./randInt')
var map = require('../array/map')
var precise = require('../number/enforcePrecision')
var isNumber = require('../number/isNumber')
var isBoolean = require('../lang/isBoolean')

function sample (lower, upper, num, precision) {
  var sample = []
  sample.length = num

  if (isNumber(precision)) {
    // a number will generate decimal precision
    return map(sample, function () {
      return precise(rand(lower, upper), precision)
    })
  } else if (isBoolean(precision)) {
    // true or false will generate a set of integers
    return map(sample, function () {
      return randInt(lower, upper)
    })
  } else {
    // undefined or any other type generates normal set
    return map(sample, function () {
      return rand(lower, upper)
    })
  }
}

module.exports = sample

@@ -90,16 +90,21 @@
 ar rand 
+     
 = requir
@@ -119,23 +119,25 @@
 d')%0Avar 
-randInt
+map      
  = requi
@@ -145,244 +145,480 @@
 e('.
-/randInt')%0Avar map = require('../array/map')%0Avar precise = require('../number/enforcePrecision')%0Avar isNumber = require('../number/isNumber')%0Avar isBoolean = require('../lang/isBoolean')%0A%0Afunction sample (lower, upper, num, precision) %7B
+./array/map')%0Avar randInt   = require('./randInt')%0Avar isFinite  = require('../number/isFinite')%0Avar isBoolean = require('../lang/isBoolean')%0Avar precise   = require('../number/enforcePrecision')%0Avar assert    = require('assert')%0A%0Afunction sample (lower, upper, size, precision) %7B%0A  assert(isFinite(lower), 'Expects lower bound to be a number')%0A  assert(isFinite(upper), 'Expects upper bound to be a number')%0A  assert(isFinite(size), 'Expects sample size to be a number')%0A
 %0A  v
@@ -650,19 +650,20 @@
 ength = 
-num
+size
 %0A%0A  if (
@@ -668,14 +668,14 @@
  (is
-Number
+Finite
 (pre
@@ -760,34 +760,13 @@
 le, 
-function () %7B%0A      return
+() =%3E
  pre
@@ -800,22 +800,16 @@
 ecision)
-%0A    %7D
 )%0A  %7D el
@@ -919,34 +919,13 @@
 le, 
-function () %7B%0A      return
+() =%3E
  ran
@@ -938,30 +938,24 @@
 ower, upper)
-%0A    %7D
 )%0A  %7D else %7B
@@ -1038,34 +1038,13 @@
 le, 
-function () %7B%0A      return
+() =%3E
  ran
@@ -1062,14 +1062,8 @@
 per)
-%0A    %7D
 )%0A  

update random/sample