John and Graham,
Since this method will probably generate odd totals of households in the four groups would it be possible to do this a different way? I slept on it and thought of this:
Maybe put all the records in a temporary table, then pick a random 1/4 of the records and remove them to a tempgroup1 table, then take a random one third of the remaining households and move them to a tempgroup2 table, then take half of those remaining and remove them to a tempgroup3 table. Then assign the group numbers as required and move them all back to the original table. Is that possible?
Russ
Hi Russ
You don't actually need the Mod operation, because the Rnd() function returns a number between 0 and 0.99999999… Thus, multiplying the result by 4 will give a number between 0 and 3.99999999…
You need to use the Int function to ensure this result is always rounded DOWN, and then finally add 1 if you want (1,2,3,4) instead of (0,1,2,3).
Thus, your UPDATE query will look something like this:
UPDATE [Your Table Name] SET [Group Number]=Int(Rnd([House Number]) * 4) + 1;
Best regards,
Graham
---In MS_Access_Professionals@yahoogroups.com, <dyspoz2@...> wrote :
John,
Should I put this in the query field where I want the random number applied? Such as in the Group Number field? And I do want the groups to be numbered 1-4 so would the statement be modified like this?
Group: (Rnd([Household Number]) * 4) Mod 5
Russ
You can use the Rnd function to do what you want in a query.
Group: (Rnd([Household Number]) * 4) Mod 4
That will give you a random number between 0 and 3 to assign your groups. Add 1 if you want groups 1 through 4. Use that in an UPDATE query to assign the values.
NOTE: You WILL get random numbers, but there's no guarantee that an equal number of households will be assigned to each group.
John Viescas, Author
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2016.0.7998 / Virus Database: 4756/14048 - Release Date: 03/02/17
Posted by: Russ <dyspoz2@cox.net>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (6) |
Tidak ada komentar:
Posting Komentar