How to use the pickset function from chance
Find comprehensive JavaScript chance.pickset code examples handpicked from public code repositorys.
29 30 31 32 33 34 35 36 37
_.isArray(options.array) && _.isInteger(options.quantity) && options.quantity >= 0 && options.quantity <= options.array.length ) { replacement = chance.pickset(options.array, options.quantity); } else { replacement = '$missing'; }
21
116
3
102 103 104 105 106 107 108 109 110 111
* Default is a sentence with a random number of words from 12 to 18. * @param {number} length * @param {number} words */ sentence(length = rand(12, 18), cn = false) { return cn ? chance.pickset(chinese.words, length).join('') : chance.sentence({ words: length }); }, /** * Return a random text words.
5
0
1
+ 11 other calls in file
59 60 61 62 63 64 65 66 67 68
}); } function randRecording (createdUsers) { const user = chance.weighted(createdUsers, [...Array(196).fill(0.4), 10.8, 10.8, 0, 0]); const randomText = chance.pickset(recordingsJSON, 2).reduce((a, b) => a + b.text, ''); return Recording.build({ text: randomText, personality: [ { "quality": "Adventurousness", "score": Math.random() },
3
12
6
+ 3 other calls in file
GitHub: sylvainv/pg-manati
149 150 151 152 153 154 155 156 157 158
test.app.post('/data/misc_data') .set('Content-Type', 'application/json') .send(data = { 'money_data': chance.dollar({max:999}), 'bool_data': chance.bool(), 'mood_data': chance.pickset(['sad', 'ok', 'happy'], 1)[0], 'bit_data': '101' }) .expect(200, [data]) .end(cb);
2
5
4
209 210 211 212 213 214 215 216 217 218
for (key in pickedInst) { ridsStr.push(key); } pickedRid = chance.pickset(ridsStr, 1); pickedRid = Array.isArray(pickedRid) ? pickedRid[0] : pickedRid; var rdef = lwm2mId.getRdef(pickedOid, pickedRid); if (rdef.access !== 'E') {
1
5
6
+ 7 other calls in file
GitHub: jreina/marie-kondo
5 6 7 8 9 10 11 12 13
* @param {Array<string>} files * @param {number} probability A number between 0 and 1 describing how likely a given file is to be marked. */ function mark(files, probability = 0.05) { const filesToRemove = Math.floor(files.length * probability); return chance.pickset(files, filesToRemove); } module.exports = mark;
0
3
2
7 8 9 10 11 12 13 14 15 16
quests.forEach(function (quest) { questsMap[quest.name] = quest }) function generateDailies () { const dailies = chance.pickset(quests, 5) dailies.forEach(function (daily, index) { const dbQuest = new Quest({ name: daily.name })
2
2
6
GitHub: ejfox/coachartie_discord
384 385 386 387 388 389 390 391 392 393
if (!memories) { console.error('Error getting random memories') return []; } if (memories && memories.length > 0) { const randomMemories = chance.pickset(memories, numberOfMemories); return randomMemories//.map(memory => memory.value); } return [];
0
2
0
+ 2 other calls in file
18 19 20 21 22 23 24 25 26 27
return undefined } function pickSet(set, quantity) { if (is.array(collection)) { return chance.pickset(collection, quantity) } if (is.plainObject(collection)) { return chance
0
0
1
+ 5 other calls in file
58 59 60 61 62 63 64 65 66 67
const locationPopulationSum = locationPopulations.reduce((sum, arr) => { return arr.reduce((a, b) => a + b, sum); }, 0); const numLocations = chance.integer({min: 10, max: 20}); const chosenLocations = chance.pickset(possibleLocations, numLocations); newCity.children = chosenLocations.map(([x, y]) => Building({ dim: [city.geometry.dim[0] / 5, city.geometry.dim[1] / 5, city.geometry.dim[2]], position: [x / 5, y / 5]
0
0
11
chance.word is the most popular function in chance (344 examples)