如何只生成一次从 1 到 100 的随机数? [英] How to generate a random number from 1 to 100 only once?

查看:16
本文介绍了如何只生成一次从 1 到 100 的随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在AS3中生成一个从1到100的随机数,不会生成两次.所以我需要生成每个数字,直到所有数字都完成.我该怎么做?

I need to generate a random number from 1 to 100 in AS3 that will not be generated twice. So I need every number be generated until all the numbers are complete. How can I do that?

推荐答案

用数字 1 到 100 填充数组.

Fill an array with the numbers 1 to 100.

随机打乱它(使用Fisher-Yates shuffle).

Randomly shuffle it (use Fisher-Yates shuffle).

从第一个数组索引开始取每个数字...

Take each number starting from the first array index onwards...

这篇关于如何只生成一次从 1 到 100 的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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