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

Question about Randomize

I've got an A2K database with a report that generates any number of
random medical record numbers. The user inputs how many numbers they
want and report uses the Randomizer function found on "The Access Web"
site to generate these numbers. Out of 38000 records, there are 900
unique medical record numbers. I run the randomizer function on a
query of these unique medical record numbers.

The user states there are too many duplications from one report to
another. They consistently ask for 100 numbers. When I run the
reports I see some duplicates on occasion but not enough for me to
think there's a problem with the function.

Anybody had this issue before and if so how did you solve it? Below
is the query and function I use if it's of any help.

Thanks for any help or advice.

Here's my query to return random numbers:

SELECT TOP 100 qselStep3UniqueMRs.MedicalRecordNumber FROM
qselStep3UniqueMRs WHERE Randomizer() = 0 ORDER BY
Rnd(IsNull(qselStep3UniqueMRs.MedicalRecordNumber) * 0 + 1);

Here's the function:

Static AlreadyDone As Integer

If AlreadyDone = False Then Randomize: AlreadyDone = True
Randomizer = 0

Does anybody see a problem
Nov 13 '05 #1
1 3405
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The Randomizer can return duplicate numbers 'cuz it is a singular event
for many items. IOW, each time the randomizer function is run it
doesn't exclude previously selected numbers; therefore, duplicate
numbers can be re-selected by the randomizer. The way I avoided the
duplicate problem was to keep the list of selected numbers in an array.
When the randomizer selects a number, that number is compared to the
array of already selected numbers. If the newly selected number already
exists in the array it is discarded and the process repeated.

Here is the procedure I use. You may use it as a starting point for
your solution.

Sub getRandomNumbers(ByVal lo As Integer, ByVal hi As Integer, _
ByVal toSelect As Integer, result() As Integer)
' Purpose:
' Return an indicated number of unique random numbers
' from a defined population.
' In:
' lo The bottom number in the population
' hi The top number in the population
' e.g: lo = 73, hi = 250
' toSelect The number of items between lo & hi to return.
' Out:
' result() The resulting array of integers
' Created:
' mgf 25may99
' Modified:
' mgf 28mar2001 Changed from a Function to a Sub. Instead
' of returning an array of Booleans, whose
' index is the random number, return an array
' of numbers whose value is the random number.
'

ReDim items(lo To hi) As Boolean
Dim selected As Integer
Dim num As Integer

' Seed the randomizer
Randomize

' Generate the array of unique, random items
Do While selected < toSelect
' Get a number between lo and the hi boundaries
' * From the VBA Help file on Rnd() *
num = Int((hi - lo + 1) * Rnd + lo)
If items(num) = False Then
' Mark the item as selected
items(num) = True
' Keep track of the number of items selected.
selected = selected + 1
' Load the results array
result(selected) = num
End If
Loop

End Sub
' ---- how to call the subroutine
Function testGetRandom()
' test getRandomNumbers subroutine

Const lo As Integer = 25 ' Low boundary of population
Const hi As Integer = 1000 ' High boundary of population
Const itms As Integer = 10 ' Number of items to return

ReDim result(1 To itms) As Integer
getRandomNumbers lo, hi, itms, result()

Dim i As Integer
For i = 1 To itms
Debug.Print result(i)
Next i

End Function

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQUZFO4echKqOuFEgEQIW9ACg13AlDwixwzrXRTtCBUe5wB MI/msAmgLl
+aAok2RaT9sTGRAC2DyCnZF4
=sZfg
-----END PGP SIGNATURE-----
Ellen Manning wrote:
I've got an A2K database with a report that generates any number of
random medical record numbers. The user inputs how many numbers they
want and report uses the Randomizer function found on "The Access Web"
site to generate these numbers. Out of 38000 records, there are 900
unique medical record numbers. I run the randomizer function on a
query of these unique medical record numbers.

The user states there are too many duplications from one report to
another. They consistently ask for 100 numbers. When I run the
reports I see some duplicates on occasion but not enough for me to
think there's a problem with the function.

Anybody had this issue before and if so how did you solve it? Below
is the query and function I use if it's of any help.

Thanks for any help or advice.

Here's my query to return random numbers:

SELECT TOP 100 qselStep3UniqueMRs.MedicalRecordNumber FROM
qselStep3UniqueMRs WHERE Randomizer() = 0 ORDER BY
Rnd(IsNull(qselStep3UniqueMRs.MedicalRecordNumber) * 0 + 1);

Here's the function:

Static AlreadyDone As Integer

If AlreadyDone = False Then Randomize: AlreadyDone = True
Randomizer = 0

Does anybody see a problem


Nov 13 '05 #2

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

Similar topics

2
by: Fieldmedic | last post by:
I'm trying to determine the best way to randomize a set of array items. I'm thinking that I could use an arraylist and have it use the lower and upper bounds as the limits. Any suggestions? ...
7
by: Torbjørn Morka | last post by:
I am currently working with a small program using BCB 6, and this is my question. When clicking the button the code is this...:...
3
by: Gaffer | last post by:
Hello Is there a way in which I can make certain parts of Html on my website random so that each viewer will see different material if they refresh the page or come back onto the website later?...
3
by: Thomas Scheiderich | last post by:
I am curious as to why ASP.NET returns values a different way from VB or VB.net (or can you use both). In my one book I have it returning using a return statement ...
4
by: Mr. x | last post by:
Hello, randomize is a function in vbscript. What is the function for vb ? (I have tried to use that command in the script in web-service of .net, which used VB and not VBScript). Thanks :)
2
by: Rich | last post by:
Here is what I am trying for randomizing 2 numbers in the same subroutine so that they are not equal to each other: Dim j As Integer, k As Integer j = New System.Random().Next(0, 10) k = New...
1
by: Badass Scotsman | last post by:
Hello, This code is supposed to generate a random string each run, however I have had it live on a few sites, and it seems to create repeat strings all over the place. ...
1
by: VBSTUDENT | last post by:
I am just wondering if there is a way to randomize the aritmetic operators in code, I know how to randomize numbers but I am not sure if it is possible to randomize operators. Any help would be...
5
by: gggram2000 | last post by:
Hi, I'ved spent two full days trying to find a solution, I can randomize numbers between two ranges and it works fine, But my problem is when i want to randomize five numbers that I got. eg. I...
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
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...
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
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...

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.