唯一编号C#网

唯一编号C#网

问题描述:

嘿那里.

如何在vc#中获得1到75之间的3个唯一数字?

它不是作业,只是需要使用哪种方法的一些帮助

//我有一个程序,该程序应生成3个随机唯一数字,并应将其打印在3个不同的标签上. (第一名,第二名,第三名)

我已经开发出一种解决方案,但某些东西(不是很常见)输出2个相等的数字

因此,是否有任何函数或方法每次在一个范围(例如)之间生成唯一的数字. (1,75)

ty all:)

hey there.

how can i get 3 unique numbers between 1 and 75 in vc#?

it is not homework just need some help on which method to use

// i have a program that should generate 3 random unique numbers that should be printed out on 3 different labels. (1st winner, 2nd winner, 3rd winner)

I already developed a solution but somethimes (not often) it ouputs 2 equal numbers

so is there any function or method that generates unique numbers everytime between a range eg. (1, 75)

ty all :)

您尝试过类似的东西吗?

Have you tried something like this?

System.Random RandNum = new System.Random();
Label1.Text = RandNum.Next(1, 75).ToString();
Label2.Text = RandNum.Next(1, 75).ToString();
Label3.Text = RandNum.Next(1, 75).ToString();





croell写道:

我已经开发了一种解决方案,但是某些(不是经常)它输出2个相等的数字

I already developed a solution but somethimes (not often) it ouputs 2 equal numbers



如果您要生成随机数,则有可能两次生成相同的数字.但是,如果您不希望仅将生成的随机数存储在数组中,并确保数组中的每个元素在添加之前都是唯一的,那么在这种情况下,如果数组中已经存在任何数字,则生成一个新数.一旦获得数组中的所有数字,就将这些值分配给所需的标签.



If you are generating random number there might be a chance that same number can be generated twice. But if you don''t want that just store the generated random number in a array and make sure that each element of the array is unique before adding to it, if any number is already present in the array in that case generate a new number. Once you got all the number in the array assign these values to the desired labels.