random i/o 
Author Message
 random i/o


I have a problem concerning random i/o.
I want to get random numbers from a file that I read from disk.
The file looks like:    40
                        50     # numbers between 40-99
How do I access the file and pick a number randomly.
I should only pick number that exist in the file,
for instance 43 the first time and then 51 the second time and so on.

Is there a simple solution to this ?
Be glad for some help.

Sincerely Jonas,


Mon, 19 Apr 1993 15:27:00 GMT  
 random i/o
<I want to get random numbers from a file that I read from disk.

Various methods:
1. Spill coke on the floppy.
2. Attach a large (>5HP) electric motor in the next outlet. Turn the motor
   on and off rapidly while reading the disk drive.
3. Use one of those old 20mb disk drives from the early days of the AT.
4. Tap on the drive case with a hammer while it's reading.
5. Wrap a spark plug wire around the cable leading to the disk drive.
   Turn on your car.
6. Expose your computer to one of those virus programs.
7. Operate the computer during a thunderstorm.

:-) :-) :-)

Mon, 19 Apr 1993 20:00:00 GMT  
 random i/o
For BSD or HP-UX systems, here's select.c:

    #include <stdio.h>
    #include <time.h>

    main(argc, argv)
    int argc;
    char *argv[];
        char s[80];
        struct timeval t;
        int i, j;

            gettimeofday(&t, 0);
            j = srand(t.tv_usec);

            freopen(argv[2], "r", stdin);


            i = rand() % atoi(argv[1]) - 1;

            while(i-- > 0)



    select `wc -l inputfile` inputfile

For systems without gettimeofday() or some other rapidly changing value,
you will have to find some other means of seeding the generator.

Dave Decot
Hewlett-Packard Company

Mon, 19 Apr 1993 23:09:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. random rant on random files

2. A truly random $random??

3. ? generating random uniform and binomial random deviates for BIG integers

4. Unit tests and random.Random()

5. Random number not random?

6. random behavior in random module?

7. Random Number Generator to produce SAME random number from 12:00am-11:59pm

8. Opening random line from file with random.shuffle()

9. Random Value

10. J random-number generator: what is used?

11. Quasi Random numbers

12. Instructions for testing the COM Random Stream Sample


Powered by phpBB® Forum Software