0

I have searched and although I see this addressed in Python and PHP, I don't see it using JS. This script randomizes order on refresh and I would like the numbers to be randomly generated as well as the order. The order part is already working, but I don't want it limited to numbers I input (150, 375 and 900 in this example). I'm going to have about 50 variables but I've just listed three to keep it short here.

I would also like to understand how to control the place values permitted, so I could have xx,xx,xx, etc./ xxx,xxx,xxx etc. and also how to state a range, so it could include xx,xxx,xxxx

Lastly I would be very keen to understand how to limit the generated numbers to meet certain profiles, like all tens (670,320,980,410,650), twenty-fives (375,925,400,850,175, etc.). This would be extremely helpful.

I'm sorry this is just beyond my ability, and I have tried and tried. I operate a school in India where I teach math, and we have had great success teaching number recognition and counting in English and Hindi using printed charts of numbers that fit different criteria like this, and I would like to adapt it to a mobile app, just to let you know why I'm asking. Many thanks.

var contents=new Array()
contents[0]='150'
contents[1]='375'
contents[2]='900'
*/
var spacing = "<br />"
var the_one
var z = 0
while (z<contents.length){
the_one=Math.floor(Math.random()*contents.length)
if (contents[the_one]!="_selected!"){
document.write(contents[the_one]+spacing)
contents[the_one]="_selected!"
z++
  }
}
  • 2
    Regarding "how to limit the generated numbers": If you can generate a random integer, you can generate a random multiple of a number with simple multiplication (E.g. Random int * 10 == random multiple of 10) – DBS Jul 14 '20 at 13:40
  • 1
    Looks like you know how to generate a random integer. If not, you can read about it in [this answer](https://stackoverflow.com/a/1527820/1563833). As for how to "control the place values permitted", to generate a number that is "twenty-fives" you generate a random integer and multiply it by 25. Think of it like coins. This is like asking to select a random number of 25-cent pieces. You just have to divide to adjust the max based on the value of the coin. Like you know how to choose at most 4 25-cent pieces if you don't want to exceed 1 dollar. (100 / 25 = 4) – Wyck Jul 14 '20 at 13:54
  • I don't understand how to generate the random integer in combination with the random order as laid out in my script above. I don't know what goes in the space where I currently have specific declared numbers. Do I replace the lines that say "contents" entirely? –  Jul 14 '20 at 14:00

0 Answers0