Random numbers using Javascript
Nov 15, 2021
I developed this little random generator for a recent competition we held. We had a number of prizes and people could entry how many times they wanted. Each entry was added to an excel spreadsheet. We wanted to randomly select the winners from those listed in the spreadsheet. With the random generator, you enter the number of prizes on offer and then the number of entries (total number of rows in the spreadsheet) , click the Generate button and the unique winning numbers are displayed. (Could also be used to select random lotto numbers...) Cheers Gerry
23 Replies
This is such a creative use of Storyline 360, Gerry! I absolutely love this idea for generating random numbers/winners. Are you able to share the story file?
Thanks Sarah! sure thing please find SL file attached.
Thank you for sharing your story file with the community, Gerry!
Great idea, can you share the story file? I also want to learn it and apply it to my mini games of drastic ds emulator apk
Hi Ani, the storyline file is attached to the 2nd comment above.
If you are ever in need of making sure the random number is non-repeating...
https://community.articulate.com/discussions/articulate-storyline/ensuring-a-random-number-is-not-re-picked#reply-492986
See it in action here.
Thanks for the script on how to achieve this Owen, it will come in handy :)
My pleasure Gerry.
thanks
This is a particularly inventive utilization of Storyline 360, Gerry!
I totally love this thought for producing arbitrary numbers/victors. Is it true that you are ready to share the story document?
It is shared in his reply here: https://community.articulate.com/discussions/building-better-courses/random-numbers-using-javascript#reply-771856
Hello Gerry, Hope you are doing good. I have downloaded the attached file but am unable to open the file. Which software do you recommend to open this type of file?
Regards
Karl Woodson
wamods.net
Hey Karl, I am doing well thanks! hope you are also doing well😀. I used Articulate Storyline 360 to develop the random number generator. Cheers
Hi Asad! Gerry has so many creative ideas. He shared the file in the comments here.
Thanks Sarah :)
This post was removed by the author
You are a savior, thanks !!
No problem.
Amazing! It is looking great.
Nice story gerry, i like your effort.
hi,
Generating random numbers using JavaScript is a common task and can be done using the built-in Math.random() function. Here's how to generate random numbers in JavaScript:
To generate a random decimal number between 0 and 1, use the following code
You unlocked one of my memory!!!
This was my first test during a job interview when I started as Web programmer. I was 21 ... such a great time!
Here's an example of how to generate random numbers using JavaScript:
// Generate a random integer between a minimum and maximum value function randomInteger(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // Generate a random floating-point number between a minimum and maximum value function randomFloat(min, max) { return Math.random() * (max - min) + min; } // Example usage console.log(randomInteger(1, 10)); // Generate a random integer between 1 and 10 console.log(randomFloat(1.0, 5.0)); // Generate a random floating-point number between 1.0 and 5.0
The
randomInteger()
function generates a random integer between a minimum and maximum value, inclusive of the minimum and maximum values. TherandomFloat()
function generates a random floating-point number between a minimum and maximum value, exclusive of the maximum value.Note that the
Math.random()
function returns a random floating-point number between 0 and 1, but not including 1. By multiplying this value by the difference between the maximum and minimum values and adding the minimum value, we can generate a random number within the desired range.Great job, Gerry! This random generator sounds super handy for competitions. Thanks for sharing this Javascript solution! Cheers!