Hacking - The Art of Exploitation, 2nd Edition

(Romina) #1

102 0x200


815015288


1315541117


2080969327


450538726


710528035


907694519


1525415338


1843056422


random values from 1 to 20
2 3 8 5 9 1 4

20


reader@hacking:~/booksrc $ ./a.out
RAND_MAX is 2147483647
random values from 0 to RAND_MAX
678789658
577505284
1472754734
2134715072
1227404380
1746681907
341911720
93522744
random values from 1 to 20
6
16
12
19
8
19
2
1
reader@hacking:~/booksrc $

The program’s output just displays random numbers. Pseudo-randomness
can also be used for more complex programs, as you will see in this section’s
final script.

0x287 A Game of Chance


The final program in this section is a set of games of chance that use many
of the concepts we’ve discussed. The program uses pseudo-random number
generator functions to provide the element of chance. It has three different
game functions, which are called using a single global function pointer, and
it uses structs to hold data for the player, which is saved in a file. Multi-user file
permissions and user IDs allow multiple users to play and maintain their own
account data. The game_of_chance.c program code is heavily documented,
and you should be able to understand it at this point.
Free download pdf