随机填写四个不同数字的列表

Han*_*üdi 5 c# random

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

提前致谢!

fub*_*ubo 9

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();
Run Code Online (Sandbox Code Playgroud)

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

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

  • @Enigmativity nah ..它在硬编码和计算的意义上不那么通用.结果将是`int`,而第一个可以导致数组中的任何类型. (3认同)