473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

shuffle two fields of a Db differently! but retain ability to relink them

in a Db there are 2 fields which contain 'matching' data. (there are other columns too)
A Genesis
B Exodus
C leviticus
D Numbers
E Deutronomy

I want to shuffle both columns so they are both randomly mixed up
B Numbers
A Exodus
C Detronomy
E Leviticus
D Genesis

How do I do it?
I have explored the random function but that randomises the records but keeps each record intact.

I then want to print these two columns to a report which numbers each line - easy enough once I have the query BUT I want to print an 'answer page ' at the end of the report which will look like this:-

1 B Numbers (5)
2 A Exodus (1)
3 C Detronomy (4)
4 E Leviticus (3)
5 D Genesis (2)

I thought of appending a unique ID string to each pair and only displaying the first part of the string e.g
A@1 Genesis@1
etc and I can do this but maybe there is a simpler way.
Lastly supposing I would want to keep the order of column one and only shuffle column two?
Thanks for any advice!
Feb 5 '07 #1
6 2273
Rabbit
12,516 Expert Mod 8TB
in a Db there are 2 fields which contain 'matching' data. (there are other columns too)
A Genesis
B Exodus
C leviticus
D Numbers
E Deutronomy

I want to shuffle both columns so they are both randomly mixed up
B Numbers
A Exodus
C Detronomy
E Leviticus
D Genesis

How do I do it?
I have explored the random function but that randomises the records but keeps each record intact.

I then want to print these two columns to a report which numbers each line - easy enough once I have the query BUT I want to print an 'answer page ' at the end of the report which will look like this:-

1 B Numbers (5)
2 A Exodus (1)
3 C Detronomy (4)
4 E Leviticus (3)
5 D Genesis (2)

I thought of appending a unique ID string to each pair and only displaying the first part of the string e.g
A@1 Genesis@1
etc and I can do this but maybe there is a simpler way.
Lastly supposing I would want to keep the order of column one and only shuffle column two?
Thanks for any advice!
To retain the ability to relink them just have another table.

As for random arrangement...
Store A, B, C, etc. in one table and Store Numbers, Genesis, Leviticus, etc. in another table. Randomly get one row from each table and insert the combination into a third table. Then, delete the rows you used from the first 2 tables. Loop till the first 2 tables are empty.

Of course, each time you do this you'll need to repopulate the first 2 tables. So perhaps keep a backup of each to restore them.

Maybe someone else can provide a better solution but this is the best I can think of right now.
Feb 5 '07 #2
nico5038
3,080 Expert 2GB
1) update your *table* with a RND([some unique numeric field])
2) then create a query for the sort of the *table* on the filled/updated field.
Here you can even use a TOP 3 to get just the first three when needed.

Nic;o)
Feb 5 '07 #3
Rabbit
12,516 Expert Mod 8TB
1) update your *table* with a RND([some unique numeric field])
2) then create a query for the sort of the *table* on the filled/updated field.
Here you can even use a TOP 3 to get just the first three when needed.

Nic;o)
Doesn't this run the risk of repeating numbers? And he'd still have to seperate his two fields into different tables.
Feb 5 '07 #4
nico5038
3,080 Expert 2GB
Hardly chance for a dupe when you use an autonumber as Seed for the RND() function.
Best to have two append queries filling the records into a newly created table1 and table2. Now the autonumber can be used to JOIN the two into a query showing the result.

Nic;o)
Feb 5 '07 #5
A bit risky joining on autonumber. If ever the tables get out of synch you run the risk of losing the join. Also appending and deleting records to/from a table bloats a database unnecessarily. I'd rather have two queries sorting both lists at random and then combining them. However if you have that for 5 records you end up with a query of 25 unless you can force a join on something so I am a bit stuck. (unless I then ask for the max 5 records of the expression which strips the appended number string off the end of the field - see my earlier post.
Thanks for all the support!
Feb 5 '07 #6
nico5038
3,080 Expert 2GB
Using a DROP TABLE and CREATE TABLE will limit the bloat and when you apply a weekly compact, you'll need a lot of rows and runs to exhaust Access :-)
No problem to join on autonumbers, just check afterwards or the number of rows is the same as from the originaltable when you have doubt's.

Nic;o)
Feb 6 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
24
by: Joerg Schuster | last post by:
Hello, I am looking for a method to "shuffle" the lines of a large file. I have a corpus of sorted and "uniqed" English sentences that has been produced with (1): (1) sort corpus | uniq >...
6
by: CaseyB | last post by:
If I wanted to create a game like Solitaire that would first randomly shuffle a deck of cards, I figured out that all I had to use is the Random() class or rnd and make sure I use the Randomize...
0
by: phillip.s.powell | last post by:
I have a very strange case where one entire row's set of fields literally "shuffled"... e.g., "phone" became "email", "email" became "address2", "address2" became "url", "url" became "resume", etc....
0
by: RobAMacAF | last post by:
Here is my prediciment. I have a database with a form. It in the people can pick a main category, then sub category, then it shows a list of questions from that in a sub form. I am trying to find a...
1
by: RobAMacAF | last post by:
Here is my prediciment. I have a database with a form. It in the people can pick a main category, then sub category, then it shows a list of questions from that in a sub form. I am trying to find a...
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
4
by: Aamir Mahmood | last post by:
Hi everyone, I have to write a function to shuffle a collection. If anyone has any idea on how to implement it please share with me. The signature of function is: ICollection...
2
by: rubyhuang | last post by:
the problem is A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus: 0 1 2 3 4 5 6 7 8 9 10 11 12.....39 40 41 42 43 44 45 46...
11
by: whodgson | last post by:
I`m trying to write a shuffle function to shuffle a sorted array with an even number of elements but it won`t print past the first 2 elements as shown below. When i print the temp array it only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.