Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 945 Bytes

File metadata and controls

39 lines (30 loc) · 945 Bytes
layout language permalink command io
api-command
JavaScript
api/javascript/sample/
sample
sequence
selection
stream
array
array
array

Command syntax

{% apibody %} sequence.sample(number) → selection stream.sample(number) → array array.sample(number) → array {% endapibody %}

Description

Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement.

If the sequence has less than the requested number of elements (i.e., calling sample(10) on a sequence with only five elements), sample will return the entire sequence in a random order.

Example: Select 3 random heroes.

r.table('marvel').sample(3).run(conn, callback)

Example: Select and stratify 3 random heroes by belovedness.

r.table('marvel').group('belovedness').sample(3).run(conn, callback)