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

How can I choose random data

i have large amount of data- i want to choose from it random
one record only every time
Jul 5 '10 #1
2 1730
NeoPa
32,556 Expert Mod 16PB
We'd like to help if we can, but there is too little here to enable us to understand even what you're asking. Please explain the question in more than a single sentence, giving info we'd need to understand the question.
Jul 5 '10 #2
ADezii
8,834 Expert 8TB
@Marwa Ahmed
Here is a little System which I created, that will return the Primary Key Value of a Random Record within a Data Set. Once you have this PK Value, you will now have the capability to Filter for this Single Record in any manner you so desire. For this Demo, I used the Employees Table of the Northwind Sample Database with a couple of extra Records added. Any questions, please feel free to ask. I commented the code as much as possible without trying to be annoying (LOL):
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rstRandom As DAO.Recordset
  3. Dim lngNumOfRecs As Long
  4. Dim lngRndRec As Long
  5. Dim lngRndPKValue As Long
  6.  
  7. Set MyDB = CurrentDb
  8. Set rstRandom = MyDB.OpenRecordset("Employees", dbOpenSnapshot)
  9.  
  10. Randomize       'Seed the Random Number Generator
  11.  
  12. With rstRandom
  13.   .MoveLast: .MoveFirst     'Needed for accurate Record Count
  14.   lngNumOfRecs = .RecordCount
  15.     lngRndRec = Int(Rnd() * lngNumOfRecs) + 1       'Obtain a Randmom Record Position between
  16.                                                     '1 and lngNumOfRecs
  17.       'Move to that Random Record Position allowing for the Offset. AbsolutePosition
  18.       'Property of a Recordset may be used under certain conditions, but is not 100% reliable
  19.       .Move (lngRndRec - 1)
  20.         'Retrieve the Value of the Primary Key [EmployeeID] at this Record
  21.         lngRndPKValue = ![EmployeeID]
  22.           Debug.Print "Random Record Number is: " & Format$(lngRndRec, "0000") & " with a Primary Key Value " & _
  23.                       "of " & Format$(![EmployeeID], "0000")
  24. End With
  25.  
  26. rstRandom.Close
  27. Set rstRandom = Nothing
Sample OUTPUT for 16 Trails:
Expand|Select|Wrap|Line Numbers
  1. Random Record Number is: 0003 with a Primary Key Value of 0003
  2. Random Record Number is: 0014 with a Primary Key Value of 0015
  3. Random Record Number is: 0002 with a Primary Key Value of 0002
  4. Random Record Number is: 0012 with a Primary Key Value of 0012
  5. Random Record Number is: 0004 with a Primary Key Value of 0004
  6. Random Record Number is: 0014 with a Primary Key Value of 0015
  7. Random Record Number is: 0013 with a Primary Key Value of 0014
  8. Random Record Number is: 0006 with a Primary Key Value of 0006
  9. Random Record Number is: 0003 with a Primary Key Value of 0003
  10. Random Record Number is: 0002 with a Primary Key Value of 0002
  11. Random Record Number is: 0010 with a Primary Key Value of 0010
  12. Random Record Number is: 0013 with a Primary Key Value of 0014
  13. Random Record Number is: 0016 with a Primary Key Value of 0017
Jul 5 '10 #3

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

Similar topics

4
by: kingofkolt | last post by:
I have a directory of images, called "random". In it are the following files: 1.gif 2.gif 3.gif 4.gif I use this script to choose a random image and display it:
0
by: Tony Stephens | last post by:
I have a database table that contains a set of numbers (set X). I need to be able to generate/export a random set of survey numbers (set C) from set A with IDs that aren't in set B. Where set A is...
5
by: Yudan YI \(OSU\) | last post by:
I want to generate random data from a normal distribution, while I checked the functions, and I found rand(), which returns a pseudorandom integer between zero and RAND_MAX. I am not sure how to...
6
by: lucy | last post by:
Hello comp.lang.js.I need a script to rotate a background image on each newpage load, given the id of the element and a list (array?)of 2 or more image paths ("img1.jpg", "img2.jpg", ...).Actually,...
6
by: Maziar Aflatoun | last post by:
Hi everyone, I have the following random string generator public static string getAlphabets(int strLength) { string RandomString = ""; Random X = new Random(); for (int x=0; x < strLength;...
1
by: John | last post by:
Hi, I have 30 records in a Dataset Could you pls tell me how to get random unrepeated 15 records from my dataset!!!? -- Regads, Rochdi
19
by: Erich Pul | last post by:
hi! i got a structure, which should be filled with random integer values (it is in fact a generator for numbers like in a lotto), but these values must not be recurring, so no double occurrences...
3
by: mohaakilla51 | last post by:
Alright guys, I am working on a flashcard script... Previously I had it so that it onlty had predefined categories. People were complaining, so now I am trying to make it to where it reads...
2
by: crazyfisher | last post by:
> Dear all, > I am trying to write a stored procedure for a recipe database so that the > user can choose how many recipes from what category. > I have written this one to get 7 recipes from...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.