RANDOM #'s

  • Thread starter Thread starter Fatz
  • Start date Start date
F

Fatz

Hi-

I have the following expression in a query:

Expr1: IIf([PIN #]>49999 And [PIN
#]<60000,Rnd()*(59999-50000)+50000,IIf([PIN #]>=60000 And [PIN
#]<70000,Rnd()*(69999-60000)+60000,IIf([PIN #]>=70000 And [PIN
#]<80000,Rnd()*(79999-70000)+70000,IIf([PIN
#]>79999,Rnd()*(89999-80000)+80000,0))))

What I want this to do is provide me with a new random number for
every record in my table BASED on the value of the record. So if the
current value is >= 50,000 and less than 60,000 I want it to give me a
new random # between those amounts.

This expression works but it gives me the same random number for each
group. I think I should set up 4 modules to house the code for each
group....50,000-60,000, 60,0000-70,000, 70,0000 - 80,0000, and >
80,0000.

Any help would be appreciated! The more detailed the better since I
am a newbie!!

Thanks,
Chris
 
Try passing the primary key as a value to Rnd() in each case, i.e.:
Rnd([Pin #])

The Rnd() function does not actually do anything with the value passed in,
but it forces the query optimiser to actually call the function on every
row.
 
Thanks Allen! Perfect!

-Chris


Allen Browne said:
Try passing the primary key as a value to Rnd() in each case, i.e.:
Rnd([Pin #])

The Rnd() function does not actually do anything with the value passed in,
but it forces the query optimiser to actually call the function on every
row.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.
Fatz said:
I have the following expression in a query:

Expr1: IIf([PIN #]>49999 And [PIN
#]<60000,Rnd()*(59999-50000)+50000,IIf([PIN #]>=60000 And [PIN
#]<70000,Rnd()*(69999-60000)+60000,IIf([PIN #]>=70000 And [PIN
#]<80000,Rnd()*(79999-70000)+70000,IIf([PIN
#]>79999,Rnd()*(89999-80000)+80000,0))))

What I want this to do is provide me with a new random number for
every record in my table BASED on the value of the record. So if the
current value is >= 50,000 and less than 60,000 I want it to give me a
new random # between those amounts.

This expression works but it gives me the same random number for each
group. I think I should set up 4 modules to house the code for each
group....50,000-60,000, 60,0000-70,000, 70,0000 - 80,0000, and >
80,0000.

Any help would be appreciated! The more detailed the better since I
am a newbie!!

Thanks,
Chris
 
Back
Top