!powerball lottery command

Trying to create a command that draws 5 random, non-repeating numbers from 1-69 listed in ascending order, then a random number from 1 to 26.

Final example output format should be 09-11-20-27-59 / 11

The last part is easy: $(eval Math.floor((Math.random() * 26) + 1))

Browsing the forum I saw this code that selects non-repeating variables from a list, but you have to type how many variables to select as well as list every variable manually in chat. Maybe it can be modified.

$(eval match=$(query).match(/^(\d+) (.)$/);if(match){n=parseInt(match[1]);c=match[2].split(“,”);if(n>c.length){“The number of choices to pick was larger than the number of choices”}else{for(i=c.length-1;i>0;i–){j=Math.floor(Math.random()(i+1));x=c[i];c[i]=c[j];c[j]=x}c.slice(0,n).sort().join(“,”)}}else{“Enter the number of choices to pick, followed by a comma-separated list of choices”})

Hey @evalhelpquestion!

The first challenge of this command is to generate the list of numbers you can pick from in a concise manner:

[...Array(69).keys()].map(i => i + 1)

This will give you an array going from 1 to 69, from which you can randomly pick your 5 numbers.

And then you randomly pick 5 numbers from that array while extracting them from it so you don’t pick them twice thanks to .splice():

[...Array(5)].map(r => n.splice(Math.floor(Math.random() * n.length), 1)[0])

Once combined, and with the ball, you get the following code:

$(eval n = [...Array(69).keys()].map(i => i + 1); b = Math.floor(Math.random() * 26) + 1; `${[...Array(5)].map(r => n.splice(Math.floor(Math.random() * n.length), 1)[0]).join('-')} / ${b}`;)
1 Like

Wonderful as always, thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.