Platforms to show: All Mac Windows Linux Cross-Platform
FAQ.How to do a lottery in RB?
Feedback.
Answer: Try this function:
Example:
Feedback.
Answer: Try this function:
Example:
Sub Lotto(max as integer,count as integer,z() as integer)
// Lotto count numbers of max put into the array z beginning at index 0
dim n(0) as integer ' all the numbers
dim m as integer ' the highest field in the current array
dim i,a,b,d as integer ' working variables
'fill the array with the numbers
m=max-1
redim n(m)
for i=0 to m
n(i)=i+1
next
' unsort them by exchanging random ones
m=max*10
for i=1 to m
a=rnd*max
b=rnd*max
d=n(a)
n(a)=n(b)
n(b)=d
next
' get the first count to the dest array
m=count-1
redim z(m)
for i=0 to m
z(i)=n(i)
next
'sort the result
z.sort
End Sub
Sub Open()
// Test it
dim za(0) as integer ' the array of the numbers
lotto 49,6,za ' 6 of 49 in Germany
' and display them
staticText1.text=str(za(0))+chr(13)+str(za(1))+chr(13)+str(za(2))+chr(13)+str(za(3))+chr(13)+str(za(4))+chr(13)+str(za(5))+chr(13)
End Sub
Links
MBS Realbasic Plugins - Pfarrgemeinde Messdiener Nickenich