## Random picked numbers

## Random picked numbers

(OP)

I work on an application that requires the computer to pick out a number less than 100 every 5 minutes in 10 hrs (120 numbers are produced in 10 hrs). In those 120 numbers, the computer will pick out 12 numbers randomly at the time the computer generate the number. The application will run everyday from 7AM to 5PM.

I am stuck on how to constraint 12 numbers. Any help will be really appreciated.

Thanks a lot.

I am stuck on how to constraint 12 numbers. Any help will be really appreciated.

Thanks a lot.

GH

## RE: Random picked numbers

- nothing

- something

- depends on the random value generated.

You seem to be suggesting that you may as well generate 120 numbers at 5pm, and go from there.

> at the time the computer generate the number

What does this mean?

--

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

## RE: Random picked numbers

- After it generate this number (ie. 70), it also tells that this number is picked to be in the sample.

- There will be 120 numbers get created from 7AM to 5PM. Out of 120 numbers, there will be only 12 numbers get pick to be the sample.

Here is what it should output:

- At 7:00 AM, number picked 70, count #1, number is picked. Sample #1

- At 7:05 AM, number picked 25, count #2, number is NOT picked.

- At 7:10 AM, number picked 30, count #3, number is NOT picked.

- At 7:15 AM, number picked 32, count #4, number is NOT picked.

.......

- At 10:45 AM, number picked 99, count #xx, number is picked. Sample #2

- At 10:50 AM, number picked 22, count #xx+1, number is picked. Sample #3

.....

- At 4:20 AM, number picked 55, count #1yy, number is picked. Sample #12

.....

.....

- At 5:00 PM, number picked 21, count #120, number is NOT picked.

As a note, all the time that it picks out the sample has to be random. The output has to be printed out has the number gets generated. The sample per 10-hr day has to be 12.

I get stuck at the part that how to pick out 12 numbers randomly in the 120-count set.

Thanks for helping.

GH

## RE: Random picked numbers

One way would be to put all 120 times into an array, shuffle that array, and then pick the first 12 entries. This guarantees that you'll always get unique times.

--

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

## RE: Random picked numbers

Apropos, shuffled random sequence is not better than original one in the theory of probability sense.

If you want true (or near;) random choices, you can't use pseudo-random generators at all. In that case you need more complex approach with disk rotation speed sensors etc (at least;). It's another story.

## RE: Random picked numbers

GH

## RE: Random picked numbers

Whycan you not pre-generate them? A number that's random at 4:45 is going to be just as random at 8:20.Generate 12 random values at 8:00 and place them into an array... call it

Value. Also at 8:00, generate another 12 random numbers between 1 and 120, also placed into an array... we'll call this oneTime. Each value inTimecorresponds to a 5-minute period.Every 5 minutes, scan the

Timearray... if the current 5-minute period matches up with one listed in theTimearray, grab a number from theValuearray (or just generate the damn thing on the fly and forget about theValuearray altogether).None of your requirements make much sense, and it sounds like you're going around your elbow to get to you rear end. Why is so much complication needed for such a simple problem? There has to be a reason for the complication, be it a homework assignment that says you must do it this way or some requirement you're not letting us in on.

## RE: Random picked numbers

You've run out of time slots to generate the required number of samples.

Planning the day in advance is going to be just as effective, and be far simpler to implement than the approach you're suggesting of incrementally fiddling with probabilities to ensure that you always get 12 samples in 10 hours.

Plus if you're calling standard rand(), then you'll get EXACTLY the same sequence if you call it 120 times in a loop at 07:00 as you would calling it once every 5 minutes through the day. Once you've set the seed, it's entirely deterministic in that waiting has no impact on the result it will return next.

--

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

## RE: Random picked numbers

I already got the algorithm to check the last 12 times, which start at 16:00 and make sure that i do get no more than 12 samples that get picked.

Thanks a lot for your help.

GH

## RE: Random picked numbers

You can just say

## CODE

Then at the end of the day, pick your 12 values.