Forum Discussion
Random numbers using Javascript
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
- SarahHodgeFormer Staff
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?
- GerryMcAteer-86Community Member
- SarahHodgeFormer Staff
Thank you for sharing your story file with the community, Gerry!
- aniviaCommunity Member
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
- GerryMcAteer-86Community Member
Hi Ani, the storyline file is attached to the 2nd comment above.
- OwenHoltSuper Hero
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.
- OwenHoltSuper Hero
It is shared in his reply here: https://community.articulate.com/discussions/building-better-courses/random-numbers-using-javascript#reply-771856
- ChrisGayle-8886Community Member
You are a savior, thanks !!
- OwenHoltSuper Hero
No problem.
- JimmyAndersonCommunity Member
Amazing! It is looking great.
- FlorianThomsonCommunity Member
yeah this information is insane
- HassanIzharCommunity Member
Nice story gerry, i like your effort.
- OglesbymooreCommunity Member
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
- ErvinTCrainCommunity Member
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! - DavidWarmerCommunity Member
Here's an example of how to generate random numbers using JavaScript:
javascriptCopy code// 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. - SandraEstepCommunity Member
Great job, Gerry! This random generator sounds super handy for competitions. Thanks for sharing this Javascript solution! Cheers!