How to use the weighted function from chance

Find comprehensive JavaScript chance.weighted code examples handpicked from public code repositorys.

32
33
34
35
36
37
38
39
40
41
isAdmin: false,
email: emails.pop(),
gender: chance.gender(),
dob: chance.birthday({ string: true }),
occupation: chance.pickone(['Sales', 'Hospitality', 'Healthcare', 'Custodial', 'Accounting', 'Teaching', 'Law-Enforcement', 'Law', 'Finance', 'Engineering', 'Administration', 'Student', 'Other']),
incomeLevel: chance.weighted(['Under-$15,000', '$15,000-to-$24,999', '$25,000-to-$34,999', '$35,000-to-$49,999', '$50,000-to-$74,999', '$75,000-to-$99,999', '$100,000-to-$149,999', '$150,000-to-$199,999', '$200,000-and-over'], [11.6, 10.5, 10, 12.7, 16.7, 12.1, 14.1, 6.2, 6.1]),
ethnicity: chance.weighted(['White', 'Black', 'Hispanic', 'Asian', 'American-Indian/Alaska-Native', 'Hawaiian/Other-Pacific-Islander', 'Other'], [61, 12, 18, 6, 1, 0, 2]),
religion: chance.weighted(['Protestant', 'Catholic', 'Mormon', 'Judaism', 'Islam', 'Buddhism', 'Hinduism', 'Other', 'Unaffiliated'], [46.5, 20.8, 1.6, 1.9, 0.9, 0.7, 0.7, 3.5, 23.4]),
education: chance.weighted(['High-School', 'Some-College', 'Associate-Degree', 'Bachelor-Degree', 'Advanced-Degree'], [70, 15, 10, 4, 1]),
maritalStatus: chance.weighted(['Single', 'Married', 'Widowed', 'Divorced'], [30.7, 46.2, 10.3, 12.8]),
fork icon3
star icon12
watch icon6

+ 23 other calls in file

15
16
17
18
19
20
21
22
23
24

if (whichFish === "angel fish") {
  console.log("I am a angel fish");

  const fishBase = () => {
    const value = chance.weighted(
      ["AF1E", "AF2E", "AF3E", "AF4E", "AF5E"],
      [1, 1, 1, 1, 1]
    );
    return {
fork icon1
star icon2
watch icon0

+ 8 other calls in file

93
94
95
96
97
98
99
100
101
102
    return "none";
  }
};

const accessoryC = () => {
  const value = chance.weighted([null, "DC1E", "DC2E"], [1, 1, 1]);
  if (value !== null) {
    return {
      asset: media[value].asset,
      name: media[value].title,
fork icon1
star icon2
watch icon0

+ 7 other calls in file

56
57
58
59
60
61
62
63
64
65
//Users
function randUser() {
  return User.build({
    email: emails.pop(),
    password: chance.word({length: 6}) + chance.character({pool: '12345'}),
    isAdmin: chance.weighted([true, false], [1, 10])
  })
}

function generateUsers() {
fork icon0
star icon1
watch icon1

+ 3 other calls in file

33
34
35
36
37
38
39
40
41
42
43
    name: [chance.first(), chance.last()].join(' '),
    photo: randPhoto(),
    phone: chance.phone(),
    email: emails.pop(),
    password: chance.word(),
    isAdmin: chance.weighted([true, false], [5, 95])
  });
}


function randTitle () {
fork icon1
star icon0
watch icon0

+ 2 other calls in file

24
25
26
27
28
29
30
31
32
33
  await interaction.reply({
    content: `You need to wait ${timeLeft.seconds}s before using this command again!`,
    ephemeral: true,
  });
} else {
  const rare = chance.weighted([true, false], [10, 90]); // 10% chance of getting a rare item
  const user = interaction.user;
  const embed = new EmbedBuilder()
    .setTitle("Foraging...")
    .setDescription(`<@${user.id}> goes foraging in the wilderness.`)
fork icon0
star icon8
watch icon0

75
76
77
78
79
80
81
82
83
84

noKeywordsResponse = async () => {
  const quoteData = await request.post(apiURL)
  const quote = quoteData.body.tweetText
  const rebuttal = ['Hast thy nothing witty to say? ', 'Hast thou had enough? ', quote]
  return chance.weighted(rebuttal, [1, 1, 3])
}
noInputResponse = async () => {
  const quoteData = await request.post(apiURL)
  const quote = quoteData.body.tweetText
fork icon0
star icon0
watch icon1

+ 11 other calls in file