Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

random databases.

Posted on 2000-02-17
8
Medium Priority
?
235 Views
Last Modified: 2010-05-02
I've got a relatively small database sorted by number.

How can I sort this to display these entries in a random order, each time I run the program, and not repeat entries?
0
Comment
Question by:SRP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532715
You could add an extra field to the recordset, then fill this with a random number and order it on this.

rstRandom.Open "SELECT Number,Field1,Field2...Field3,Random = 0.0 FROM TableName",cnnDatabase,adOpenStatic,adLockOptimistic
With rstRandom
  .MoveFirst
  Do
    !Random = Rnd() * 100
    .MoveNext
  Loop Until .Eof
End With
rstRandom.Sort = "Random"

Or something like that anyway.
0
 
LVL 1

Accepted Solution

by:
georgeman earned 200 total points
ID: 2532754
Try this algorythm:

- load all db records in rs recordset

- get number records in recordset
  rs.MoveLast
  NumberRecords = rs.RecordCount

- create new empty recordset newrs

- create array(NumberRecords) as integer (or long if you have big database)

- for i=1 to NumberRecords
     'get random number
 repeat1:
     RandomNumber = Rnd()
    'if RandomNumber doesn't exist in array - add it to array
    'else goto Repeat1

     'get record number=RandomNumber from rs recordset
     rs.findfirst "number = " & RandomNumber
    'upload record from rs to newrs
  next i

- newrs is now copy of rs but organised in random order.

Regards
George
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532767
That would work as well.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:georgeman
ID: 2532777
Sorry TimCottee
I did not see your comment when I created my own.
George
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532787
That is OK, you used a different method though the thought process is obviously similar.
0
 

Author Comment

by:SRP
ID: 2537985
This is a v. good answer, and a very simple. But one brief question, will it produce a different random order each time the program runs?

OK cheers.
SAM
0
 
LVL 1

Expert Comment

by:georgeman
ID: 2540481
It depands how you will organise the process of creating of random numbers. One tip: you can use for that current date/time info so random numbers will be really random because these values are unique for every time when you start your program (or when you start this process inside program).
George
0
 

Author Comment

by:SRP
ID: 2543663
Cheers, I thought I had already accepted the answer. Obviously not!

Here are the points.

Thanks
SAM
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question