Randomize numbers with jQuery?

前端 未结 6 582
天涯浪人
天涯浪人 2020-12-05 17:44

Is there a simple jQuery way to create numbers randomly showing then a number 1 -6 is choosing after a few seconds? [Like dice]

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 18:02

    Coding in Perl, I used the rand() function that generates the number at random and wanted only 1, 2, or 3 to be randomly selected. Due to Perl printing out the number one when doing "1 + " ... so I also did a if else statement that if the number generated zero, run the function again, and it works like a charm.

    printing out the results will always give a random number of either 1, 2, or 3.

    That is just another idea and sure people will say that is newbie stuff but at the same time, I am a newbie but it works. My issue was when printing out my stuff, it kept spitting out that 1 being used to start at 1 and not zero for indexing.

提交回复
热议问题