数组中的随机数,小基本



>我正在尝试生成一个数组,该数组将具有十个变量,每个变量包含一个从 1 到 10 的随机数。随机整数不能在数组中多次出现。每次程序执行时,数组都会用不同的数字重置。例如,在英语中,我想要的基本上是:

randint[1] = random number <= 10 and >= 1
randint[2] = random number <= 10 and >= 1 and <> randint[1]
randint[3] = random number <= 10 and >= 1 and <>  randint[2]
randint[4] = random number <= 10 and >= 1 and <>  randint[3]
randint[5] = random number <= 10 and >= 1 and <>  randint[4]
randint[6] = random number <= 10 and >= 1 and <>  randint[5]
randint[7] = random number <= 10 and >= 1 and <>  randint[6]
randint[8] = random number <= 10 and >= 1 and <>  randint[7]
randint[9] = random number <= 10 and >= 1 and <>  randint[8]
randint[10] = random number <= 10 and >= 1 and <>  randint[9]

简单地说,我正在尝试在数组中以随机顺序对数字 1 到 10 进行排序。

到目前为止,我的代码如下:

For i = 1 To 10
  While rand_int[i] = prev_int
    rand_int[i] = Math.GetRandomNumber(9)+1
    prev_int = rand_int[i]
  EndWhile
EndFor

我也试过了

rand_int[1] = Math.GetRandomNumber(9)+1
for i = 2 To 10
  rand_int[i] = Math.GetRandomNumber(9)+1
  While rand_int[i] = rand_int[i-1]
    rand_int[i] = Math.GetRandomNumber(9)+1
  EndWhile
EndFor

任何帮助将不胜感激,谢谢。

轰!搞清楚了。我创建了一个数字数组,从一到十,然后我打乱了数字的顺序:

For i = 1 To 10
  Randint[i] = i
EndFor
For i = 1 To 30 'The Larger the number, the more it scrambles the order
  Rand1 = Math.GetRandomNumber(10)
  Rand2 = Math.GetRandomNumber(10)
  OldRandint = Randint[Rand1] 
  Randint[Rand1] = Randint[Rand2] 'Here we are swapping two random varibles in the array
  Randint[Rand2] = OldRandint
EndFor
For i = 1 To 10
  TextWindow.WriteLine(Randint[i])
EndFor

这会给你一个随机数

For i = 1 To 10 Step 1
  num[i]["num"] = i
  num[i]["chosen"] ="not chosen"
endfor
For i = 1 To 10 Step 1
  getnumber()
  endfor
Sub getnumber
  number=Math.GetRandomNumber(10)
  If num[number]["chosen"] = "not chosen" then
    TextWindow.WriteLine(num[number]["num"])
    num[number]["chosen"] = "chosen"
  Else 
    getnumber()
    endif
 EndSub 

你要做的是:

For i = 1 To 10
While randint[i] = randint[i-1] Or randint[i] = "" '<--- while the randint is equal to the last, it will keep generating numbers (Or while the randint is nothing)
randint[i] = Math.GetRandomNumber(10)
EndWhile
TextWindow.WriteLine(randint[i])
EndFor

相关内容

  • 没有找到相关文章

最新更新