Multiple random numbers from the same number range

B

barnettcb

Hello,

I need some assistance with a random number generator question.

First let me outline the data I will be given from the user:
1) The random numbers will be assigned to employees, so the user will
enter the number of employees, such as 8.
2) The user should then be able to input either a percentage, or a
whole number to specify how many random numbers to generate, such as
25% or 2.
3) The user will then input another percentage or whole number, such as
25% or 2, again. These will generate back up random numbers.
4) After clicking a "generate" command button, the selected random
numbers should be displayed (I will probably use a report preview).

With the above example, I should have 2 primary and 2 backup random
numbers between 1 and 8, such as 2, 5, 6, and 8. Obviously, a number
cannot be returned twice, and I need the numbers to be as random as
possible (Randomize, I believe it is called?).

Sorry if this is confusing... I will try to clarify if necessary :)
Any help is greatly appreciated!

Brooke
 
J

James A. Fortune

barnettcb said:
Hello,

I need some assistance with a random number generator question.

First let me outline the data I will be given from the user:
1) The random numbers will be assigned to employees, so the user will
enter the number of employees, such as 8.
2) The user should then be able to input either a percentage, or a
whole number to specify how many random numbers to generate, such as
25% or 2.
3) The user will then input another percentage or whole number, such as
25% or 2, again. These will generate back up random numbers.
4) After clicking a "generate" command button, the selected random
numbers should be displayed (I will probably use a report preview).

With the above example, I should have 2 primary and 2 backup random
numbers between 1 and 8, such as 2, 5, 6, and 8. Obviously, a number
cannot be returned twice, and I need the numbers to be as random as
possible (Randomize, I believe it is called?).

Sorry if this is confusing... I will try to clarify if necessary :)
Any help is greatly appreciated!

Brooke

Here's how I used a parameter query:

First I created an auxiliary table with integers up to 2 * NMax or maybe
(Pct1Max + Pct2Max) * NMax.

tblIntegers
ID AutoNumber
theInt Long
ID theInt
1 1
2 2
3 3
....
100 100

qryGetRandomNumbers:
PARAMETERS N Long, Pct1 Text, Pct2 Text;
SELECT theInt, Rnd(ID) AS RandomNumber, IIf([theInt] <= Int([N] *
Val([Pct1]) / 100), "Primary", "Backup") AS Purpose FROM tblIntegers
WHERE [theInt] <= Int([N] * (Val([Pct1]) + Val([Pct2])) / 100);

!qryGetRandomNumbers:
N 60
Pct1 10
Pct2 15

theInt RandomNumber Purpose
1 0.2546... Primary
2 0.3406... Primary
3 0.0449... Primary
4 0.4824... Primary
5 0.2060... Primary
6 0.8645... Primary
7 0.5886... Backup
8 0.7549... Backup
9 0.9279... Backup
10 0.3310... Backup
11 0.5429... Backup
12 0.0807... Backup
13 0.6344... Backup
14 0.3477... Backup
15 0.6202... Backup

!qryGetRandomNumbers:
N 50
Pct1 8%
Pct2 12%

theInt RandomNumber Purpose
1 0.5082... Primary
2 0.6588... Primary
3 0.4064... Primary
4 0.9503... Primary
5 0.6456... Backup
6 0.5161... Backup
7 0.2233... Backup
8 0.5828... Backup
9 0.7485... Backup
10 0.4565... Backup

Note that Val("8%"), Val("8") and Val("8.34%") are all 8 and Val("8.8%")
is 9. I assume the backup numbers can be used as a pool of values. I
don't prevent the same random number from being generated twice
(Wouldn't that be absolutely amazing?). Post back if you need better
than integral percentages or if a parameter query is not what you're
looking for.

I hope this helps,

James A. Fortune
(e-mail address removed)
 
B

barnettcb

Thanks James.

Let me work through this over the weekend and I will let you know how
it goes.

Brooke
barnettcb said:
Hello,

I need some assistance with a random number generator question.

First let me outline the data I will be given from the user:
1) The random numbers will be assigned to employees, so the user will
enter the number of employees, such as 8.
2) The user should then be able to input either a percentage, or a
whole number to specify how many random numbers to generate, such as
25% or 2.
3) The user will then input another percentage or whole number, such as
25% or 2, again. These will generate back up random numbers.
4) After clicking a "generate" command button, the selected random
numbers should be displayed (I will probably use a report preview).

With the above example, I should have 2 primary and 2 backup random
numbers between 1 and 8, such as 2, 5, 6, and 8. Obviously, a number
cannot be returned twice, and I need the numbers to be as random as
possible (Randomize, I believe it is called?).

Sorry if this is confusing... I will try to clarify if necessary :)
Any help is greatly appreciated!

Brooke

Here's how I used a parameter query:

First I created an auxiliary table with integers up to 2 * NMax or maybe
(Pct1Max + Pct2Max) * NMax.

tblIntegers
ID AutoNumber
theInt Long
ID theInt
1 1
2 2
3 3
...
100 100

qryGetRandomNumbers:
PARAMETERS N Long, Pct1 Text, Pct2 Text;
SELECT theInt, Rnd(ID) AS RandomNumber, IIf([theInt] <= Int([N] *
Val([Pct1]) / 100), "Primary", "Backup") AS Purpose FROM tblIntegers
WHERE [theInt] <= Int([N] * (Val([Pct1]) + Val([Pct2])) / 100);

!qryGetRandomNumbers:
N 60
Pct1 10
Pct2 15

theInt RandomNumber Purpose
1 0.2546... Primary
2 0.3406... Primary
3 0.0449... Primary
4 0.4824... Primary
5 0.2060... Primary
6 0.8645... Primary
7 0.5886... Backup
8 0.7549... Backup
9 0.9279... Backup
10 0.3310... Backup
11 0.5429... Backup
12 0.0807... Backup
13 0.6344... Backup
14 0.3477... Backup
15 0.6202... Backup

!qryGetRandomNumbers:
N 50
Pct1 8%
Pct2 12%

theInt RandomNumber Purpose
1 0.5082... Primary
2 0.6588... Primary
3 0.4064... Primary
4 0.9503... Primary
5 0.6456... Backup
6 0.5161... Backup
7 0.2233... Backup
8 0.5828... Backup
9 0.7485... Backup
10 0.4565... Backup

Note that Val("8%"), Val("8") and Val("8.34%") are all 8 and Val("8.8%")
is 9. I assume the backup numbers can be used as a pool of values. I
don't prevent the same random number from being generated twice
(Wouldn't that be absolutely amazing?). Post back if you need better
than integral percentages or if a parameter query is not what you're
looking for.

I hope this helps,

James A. Fortune
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top