如何从随机类的非序列数中选择 [英] how to choose from non sequential numbers with random class

查看:41
本文介绍了如何从随机类的非序列数中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

对于我的程序我想从一些不是偶然的数字中选择。例如,我想随机选择2,3,5,8。我必须做什么。谢谢大家。

hi all,
for my program i want to choose from some numbers that are not sequentally. for example i want to choose from 2,3, 5, 8 randomly.what i must do. thank you all.

推荐答案

制作一个数组,用你想要随机化的数字填充



使randomNumberGenerator从零到↑array.Count然后只给出数组[randomGeneratedNumber]





make an array which you will fill with the numbers you want to randomize

make a randomNumberGenerator from zero to ↑array.Count and then just give out the array[randomGeneratedNumber]


int[] asdf = {2,3,5,8};

var r = new Random();
// print random integer >= 0 and  < 4
Console.WriteLine(r.Next(4));

// print random integer >= 0 and < 4
Console.WriteLine(r.Next(0, 4);)

Console.WriteLine(asdf[r.Next(0,3)]);




把你的号码放在一张桌子里。

在0和表格大小之间随机做出(强制转换为整数)。

然后选择表格的成员[随机]。

你也可以使用词典或其他语言功能。

祝你好运。
Hi,
Put your number in a table.
Do random between 0 and size of table ( cast to integer).
Then select the member of table like Table[random].
you can also use a dictionnary or other feature of langage.
Best regards.


这篇关于如何从随机类的非序列数中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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