Logo

Programming-Idioms

History of Idiom 11 > diff from v55 to v56

Edit summary for version 56 by programming-idioms.org:
[C] Comment emphasize

Version 55

2016-11-24, 12:59:15

Version 56

2016-11-25, 09:36:34

Idiom #11 Pick a random element from a list

List x must be non-empty.

Idiom #11 Pick a random element from a list

List x must be non-empty.

Extra Keywords
choose
Extra Keywords
choose
Imports
#include <stdlib.h>
Imports
#include <stdlib.h>
Code
x[rand() % x_length];
Code
x[rand() % x_length];
Comments bubble
rand needs to be initialized by calling void srand(unsigned int);
Comments bubble
rand needs to be initialized by calling void srand(unsigned int);