生成不重复的随机数 [英] generate non repeting random numbers

查看:101
本文介绍了生成不重复的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我写这个函数来生成随机数。它有效,但我不会重复这些数字,所以任何想法。

我用图像来显示数字。


< ; script type =" text / javascript">

hey
i wrote this function to generete random numbers. it works but i don''t wont these number to be repeated so any idea.
i''m using images to show the numbers.

<script type="text/javascript">

展开 | 选择 | Wrap | 行号

推荐答案

将号码存储在数组,然后在生成一个新的随机数时检查它们。


PS。发布代码时请使用[code]标签。
Store the numbers in an array and then check against them when generating a new random number.

PS. please use [code] tags when posting code.


使用Math.round()代替Math.floor()将有助于减少重复;它会更好地分割头发。
Using Math.round() instead of Math.floor() will help reduce repetition; it splits hairs better.


请你编辑我的代码。如果不是我只是有这个代码,但我不知道在哪里放它,请帮助


< script type =" text / javascript">

<! -
can u please edit my code to do so. if not i just have this code but i dont know where to put it,, help please

<script type="text/javascript">
<!--
展开 | 选择 | Wrap | 行号


这篇关于生成不重复的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆