Generating a random number

# Thread: Generating a random number

1. Joey Tesmer Guest

## Generating a random number

Hey how do I generate a random number? I can&#039;t seem to do it. I need it to always be a random number that is never the same. Or if possible I need a way to give a number to something, but never a duplicate. I am trying to make a forum and so far I have done it but i use Session.SessionID as the number, and that is was too large. Thanks for any help.

2. Senior Member
Join Date
Dec 1969
Posts
2,958

## RE: Generating a random number

There are several ways to do it. How big can the number be? The shorter the number the higher the risk of a duplicate.

3. Senior Member
Join Date
Dec 1969
Posts
236

## DB

how are you storing the messages? SQL?

4. Joey Tesmer Guest

## RE: Generating a random number

It can be any size, from 1 to whatever i don&#039;t care

5. Joey Tesmer Guest

## RE: DB

I am storing them by Access

6. Senior Member
Join Date
Dec 1969
Posts
2,958

## Here

This is the best one I have seen. It generates a 20 digit unique ID. Name Session.("txtGuid") in the last line anything you like.<BR><BR> &#060;%<BR> tmpTemp1 = Right(String(15,48) & CStr(CLng(DateDiff("s","1/1/2000",Date()))), 15)<BR> tmpTemp2 = Right(String(5,48) & CStr(CLng(DateDiff("s","12:00:00 AM",Time()))), 5)<BR> Session("txtGUID") = tmpTemp1 & tmpTemp2<BR> %&#062;

7. Senior Member
Join Date
Dec 1969
Posts
236

## RE: DB

any reason why you are not storing them in a sequential order?<BR><BR>can you use date time as an id number?

8. Senior Member
Join Date
Dec 1969
Posts
236

## RE: DB

BTW I was hoping you were using SQL because you could easily use the newid() function built into SQL....unfortunatly I dont know if Access has a similar function.

9. Senior Member
Join Date
Dec 1969
Posts
236

## that is good <eop>

.

10. vineet1 Guest