473,382 Members | 1,355 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,382 software developers and data experts.

Pick a record at random

Ini
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.
Nov 12 '05 #1
2 6221
Ini wrote:
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.


How else would you be able to do it? I haven't seen a command to
findfirst a random record or open a table in random order? There is a
command to find a random value in a field...see Dfirst()/DLast() but you
want a record, not value. Your best option is to check out Randomize
and Rnd() in help. Once you have the random number you should move to
the first record and move the number of records minus 1.

Nov 12 '05 #2
Salad <oi*@vinegar.com> wrote in message news:<e2******************@newsread1.news.pas.eart hlink.net>...
Ini wrote:
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.


How else would you be able to do it? I haven't seen a command to
findfirst a random record or open a table in random order? There is a
command to find a random value in a field...see Dfirst()/DLast() but you
want a record, not value. Your best option is to check out Randomize
and Rnd() in help. Once you have the random number you should move to
the first record and move the number of records minus 1.


Yes you can select a random record if your recordset has a unique
number associated with each record. If you Select Top 1 then put an
Order by RND(KeyFieldName) you will get a random record return.
Run Randomize then setup your query.

Here is an example of a query that will return 1 random record. In
this case CSGTransID is an AutoNumber. Look at Randomize and Rnd help
within access if you need further explanation.

SELECT TOP 1 QryExcelExportBase.*
FROM QryExcelExportBase
ORDER BY Rnd(QryExcelExportBase.CSGTransID);
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jules | last post by:
I've searched high and low for a 3 digit number generator that will pick at random a number between 000 and 999. The only things I have found were generators that pick numbers from 0 to 999. ...
2
by: Ini | last post by:
Hi, Is there an easy way to pick at random one record out of a recordset and then leave this recordset? I was thinking about doing a recordcount of the recordset, then find at random the...
7
by: Bill | last post by:
Hello, I am trying to use a SQL Query to return a random record from an Access 2000 Database. I am using: SELECT TOP 1 Example FROM TABLE ORDER BY Rnd;
1
by: Ken Gray | last post by:
Hi all Anyone help me find a way of randomly selecting a record from a table for display on a form. Do I need to somehow re-seed the random generator? I am sure there must be an easy, simple ...
2
by: Pete via DotNetMonster.com | last post by:
Hi, I need to display a different random record or link each day. I have the random part working so that if the browser is refreshed a new record will display. I'm not sure however how to...
19
by: MaXX | last post by:
Hi, I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get...
26
by: Jimmy | last post by:
ill have a database with 1 table and 3 fields: ID FIRSTNAME LASTNAME (the ID field will be the auto incrementing index) there might be 10 records in the DB, there might be 10,000. i...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
2
by: fran7 | last post by:
Hi, I wonder if anyone could point me in the right direction. I have this script that gets a random record from my database. All records have an id, how do I instead of random just go to the next...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.