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!

Generating Random Number Field

Status
Not open for further replies.

dawnd3

Instructor
Jul 1, 2001
1,153
US
I need to create a new field that will contain a different random number each time the query is ran. (so each time they sort the list by this field it is in a random different order.) I know that there is a Randomize function and a Rnd fuction, but I am clueless on how to get them to work for my purposes. Can someone guide me? I haven't even created the field yets since I wasn't sure if I create a new blank field in the table or create it in the query design.

Thank you,

Dawn

 
thread181-1559602

Although you could probably just use the RND function directly in your query without a parameter.
 
Sorry Lameid, I am a little clueless sometimes. I need more hand holding here. Is this the function I use? ORDER BY RND(INT(NOW*ID)-NOW*ID)
Where do I put the function? In the query as a new field? Do I replace "ID" with the name of my ID field? Will this just randomly sort the records by the ID field or will it create a new field just for the purpose of randomly sorting?

THANKS!

Dawn


 
I think you will be fine to just put RND() as a new field in a query. Then on the sort by line, you will need to specify ascending (or descending for that matter... random either way).
 
I did as you suggested and it generated the same exact number for each record. (a number less than 1 with about 10 numbers after the point.)

 
Curious, I thought it would have yielded a differnet value on each call.

In any case you could use the other poster's solution and use..


RND(INT(NOW*ID)-NOW*ID)


Note ID is an autonumber field in that solution.
 
That one seems to work (although there are duplicates but for my purposes, that is just fine.) THANKS!!!
Dawn

 
Oh, and by the way, I just re-read your last post. I DID regenerate a new value on each call but it was the SAME number for all 50K plus records. I wanted a different number for each record so I could sort on it.

Thanks again,

Dawn

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top