首页 > 解决方案 > 用四个不同的数字随机填充列表

问题描述

我有一个需要以随机顺序(randomRotationVoidList)填充四个不同数字的列表,例如. 到目前为止,我发现的所有内容都会生成一个包含一定范围内随机数的列表。(90, 180, 270, 360)[270, 180, 180, 90, ...]

提前致谢!

标签: c#random

解决方案


200 个号码的样本

Random _rnd = new Random();
int[] input = { 90, 180, 270, 360 }; // dictionary of available numbers
List<int> result = Enumerable.Range(0, 200).Select(x => input[_rnd.Next(0, input.Length)]).ToList();

如果数字模式固定为另一种方法x * 90

Random _rnd = new Random();
List<int> result = Enumerable.Range(0, 200).Select(x => 90 * _rnd.Next(1, 5)).ToList();

推荐阅读