Random number generation

rainbowruthm

New member
Local time
Today, 07:43
Joined
Dec 23, 2008
Messages
7
Hi,

I am trying to create a query where each entry in my database is assigned a random number between 1 and 4. After this I will use the query to select certain entries with a specific number that fit other criteria that I will enter later.

I have tried Group: Int((4-1+1)*Rnd()+1) however this returns the same random number for each entry.

Is there a way to have a different random number for each row? And if so, would the same random number be assigned to each row each time I turn on the database, as I need to be able to refer back to which entry has which number and is therefore assigned to which group.

Thanks
 
rnd gives you a real number in the range 0 to 1

so int(rnd()*4) +1 should give you an integer in the range 1 to 4

try it and see. put it in a query and see whether you get the same number. If you do then wrap it in a function and call that. That should work

function myrand as integer
myrand = int(rnd()*4) +1
end function
 
Thanks, but when I put that in my query, each row still has the same random number. Any other ideas?
 
Rnd() is a function, a function without anything pertaining to the record is only executed once at the start of the query.

Try using Rnd(AnyFieldInYourTable)
This should trigger the Rnd every record.
 

Users who are viewing this thread

Back
Top Bottom