unity3d随机取出多个不同数
2018-03-11 09:49
274 查看
using System.Collections.Generic; using UnityEngine; public class Test1 : MonoBehaviour { private void Start() { //随机从0-100中取50个不同的数 List<int> values = TitleData.RandomNum(50, 100); foreach (var item in values) { Debug.Log("value=" + item);//50个打印出来的数,没有相同的
} } }
using System.Collections; using System.Collections.Generic; using System; public static class TitleData { private static Random random = new Random(); public static List<int> RandomNum(int wantNum,int dataCount) { HashSet<int> values = new HashSet<int>(); List<int> list = new List<int>(); int n; while (values.Count < wantNum) { n = random.Next(0, dataCount + 1); if (values.Add(n)) { list.Add(n); } } return list; } }在Unity3d中,使用UnityEngine.Random和System.Random是不同的,这里使用的是System.Random
相关文章推荐
- js从10种颜色中随机取色实现每次取出不同的颜色
- flash中随机产生20-100之间10个不同的数字,然后不能重复地随机取出这十个数字
- 随机取出1-9的不同的两个数字
- 从一个数组中随机的取出若干个不同的数
- 随机给定10个小于10的数字(出现的数字可能重复),从其中取出3个各不相同的数字可组合出多个不同的3位数,请输出这些3位数中最大的那个3位数
- js 从10种颜色中随机取色,并每次取出的颜色不同
- 随机给定10个小于10的数字(出现的数字可能重复),从其中取出3个各不相同的数字可组合出多个不同的3位数,请输出这些3位数中最大的那个3位数
- js从数组中随机取出不同的元素
- php 从一个数组中随机的取出若干个不同的数实例
- js从10种颜色中随机取色实现每次取出不同的颜色
- Javascript从数组中随机取出不同元素的两种方法
- oracle10g:从表中随机取出三条记录
- 如何从数组中随机取出多个不重复的项
- JS 在指定数组中随机取出N个不重复的数据
- 仿微信界面的只能点击,不能滑动,和随机显示不同的布局
- ss请cc来家里钓鱼,鱼塘可划分为n*m的格子,每个格子有不同的概率钓上鱼,cc一直在坐标(x,y)的格子钓鱼,而ss每分钟随机钓一个格子。问t分钟后他们谁至少钓到一条鱼的概率大?为多少?
- 发牌(从m个数字中随机选不同的n个数)
- JAVA中如何取出两个不同List对象(对象一致)中所有不同的对象的集合
- 在n个球中,任意取出m个(不放回),求有多少种不同取法
- 随机不同的数