Generate random numbers without repeating a value: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
(Generate random numbers without repeating a value en FreeBASIC) |
||
Line 115: | Line 115: | ||
{ 12 3 16 13 1 9 8 11 5 19 15 18 17 20 10 4 7 14 6 2 } |
{ 12 3 16 13 1 9 8 11 5 19 15 18 17 20 10 4 7 14 6 2 } |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>Sub pRand |
|||
Dim As Integer randCheck(20), nr = 1 |
|||
Do |
|||
Dim As Integer aleat = Int(Rnd * 20) + 1 |
|||
If randCheck(aleat) = 1 Then |
|||
Continue Do |
|||
Else |
|||
randCheck(aleat) = 1 |
|||
Print aleat; |
|||
End If |
|||
For n As Integer = 1 To Ubound(randCheck) |
|||
If randCheck(nr) = 1 Then nr += 1 |
|||
Next n |
|||
Loop Until nr = 21 |
|||
Print |
|||
End Sub |
|||
Randomize Timer |
|||
For num As Integer = 1 To 5 |
|||
pRand() |
|||
Next num |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre> |
|||
7 11 16 13 14 6 20 2 1 10 17 18 9 12 4 8 15 19 5 3 |
|||
9 6 18 16 3 14 1 8 11 2 7 20 4 13 19 12 17 5 15 10 |
|||
11 19 15 6 10 17 13 8 18 2 12 14 16 5 4 1 3 9 7 20 |
|||
5 18 13 8 4 15 16 12 7 6 1 19 2 17 9 14 10 20 3 11 |
|||
19 5 4 9 12 11 8 14 6 13 3 1 7 2 16 18 10 17 20 15 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |