Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a random number generator

Status
Not open for further replies.

OhioSteve

MIS
Mar 12, 2002
1,352
US
In Access VBA, would the following code give me a random number between 1 and 1,000,000,000?

Int(1000000000 * Rnd) + 1
 
It should. That's what the Help File examples says to do.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
This is my whole function. I think it returns a random ten digit string, with leading zeros. Tell me if it looks okay:

Public Function getReportCode()

Dim a As Long
a = Int(1000000000 * Rnd) + 1
Dim b As String
b = Right("0000000000" & a, 10)
getReportCode = b

End Function
 
You may raise overflow error as a Long (signed) can't be greater than 2147483647

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Is there a data type that lets you go to one billion?
 
OOps, sorry, I had not properly counted the 0's :~/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top