2018-10-28 pseudo random in, psudo random out

posted Oct 29, 2018, 12:08 PM by Konstantinovich Samuel
Write a c program with the following features:
  • A function that generates a random number by reading in the correct number of bytes from /dev/random.
  • A main function that:
    1. populates an array with 10 random numbers generated by your random function (print out each value)
    2. writes the array to a file
      • Do not use a loop when writing to the file
    3. reads that file into a different array
      • Do not use a loop when reading from the file
    4. prints out the contents of the second array to verify the random numbers are the same from step 1
  • Remember to use good practices, like checking return values for errors
  • Also remember to include a makefile that includes a separate run target 
github repo:
MKS65C-randomfile

 
Sample output:
Generating random numbers:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830

Writing numbers to file...

Reading numbers from file...

Verification that written values were the same:
        random 0: 198116400
        random 1: 2592608753
        random 2: 2833624368
        random 3: 3273750590
        random 4: 3548697368
        random 5: 3876828898
        random 6: 2617393183
        random 7: 1720936907
        random 8: 682596330
        random 9: 2411695830
Comments