0

Hi,

Is there an option/ or a formula to generate random numbers without duplication...Currently i'm not storing the random generated numbers in the database.
Please help me..its quite urgent

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by johnly
0

Use the Rnd function (see VB's help), with randomize. Use an array to hold the values, and use a sorting routine or just a simple For Loop structure to make sure a duplicate number is not generated.


Good Luck

0

Try using the RND([number]) in a loop to generate the nos. randomly....
TC

Hi,

Is there an option/ or a formula to generate random numbers without duplication...Currently i'm not storing the random generated numbers in the database.
Please help me..its quite urgent

0

Hi,

Is there an option/ or a formula to generate random numbers without duplication...Currently i'm not storing the random generated numbers in the database.
Please help me..its quite urgent

You can use the below function to return a random number

Public Function GetRandomNumber(Upper As Integer, Lower As Integer) As Integer
'Generates a Random Number BETWEEN the LOWER and UPPER values
Randomize
GetRandomNumber = Int((Upper - Lower + 1) * Rnd + Lower)
End Function

For preventing duplication you need to write seperate code to check each random number returned by this function against your the list of already used numbers.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.