VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Random no generator.No number is repeated once it has been generated

by Paresh Naik (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 10th March 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Random no generator.No number is repeated once it has been generated

Rate Random no generator.No number is repeated once it has been generated



Public Function Rand(Initial As Integer, Final As Integer) As Integer
 Dim n As Integer
 Static par As Integer
 Dim i As Integer
 Static arr(100) As Integer
 Randomize
Again:      n = Rnd * Final
 For i = Initial To Final
  If n = arr(i) Then GoTo Again
 Next i
 arr(par) = n
 par = par + 1
 Rand = n
End Function
Private Sub Command1_Click()
Dim p As Integer
p = Rand(0, 10) 'the range is 0 to 10.you can supply your
'range also
'Every time you click the command button the "function
'rand will generate a new random no within the range
'the limitation of the function is once it has generated
'all the nos within the range then it will not respond
'to another click as now it will not have any nos to generate
Text1.Text = p
End Sub


Download this snippet    Add to My Saved Code

Random no generator.No number is repeated once it has been generated Comments

No comments have been posted about Random no generator.No number is repeated once it has been generated. Why not be the first to post a comment about Random no generator.No number is repeated once it has been generated.

Post your comment

Subject:
Message:
0/1000 characters