Random numbers via update query ?

  • Thread starter Thread starter PEJO
  • Start date Start date
P

PEJO

Is it possible in an Access DB i've got to work with to run an update
statement that would assign random nubers to a field.
(they don't have to be Unique either).
I need to be able to run it once a week through an update statement. So I
can't use the Access autonumber by random built in functionality.

Cheers.

Pete.
 
Is it possible in an Access DB i've got to work with to run an update
statement that would assign random nubers to a field.
(they don't have to be Unique either).
I need to be able to run it once a week through an update statement. So I
can't use the Access autonumber by random built in functionality.

Sure. Say you want a random double float number between 0 and 1; run
an Update query updating the field to

Rnd([ID])

where ID is some non-negative numeric field. Passing a parameter to
the Rnd() function will force Access to call it anew on every row
rather than "saving time" by calling it once and returning the same
value for every row; a zero or positive argument to Rnd() returns the
next random number (a negative value sets the seed for the randomizing
algorithm).

If you want (say) integers from 1 to 1000000, just use

CLng(Rnd([ID]) * 1000000) + 1

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top