All pastes #365291 Raw Edit

Anonymous

public cpp v1 · immutable
#365291 ·published 2007-02-20 21:07 UTC
rendered paste body
for (int j = 0; j < COLS; j++)   randomArray[0][j] = rand() % 98 /* or whatever */	for( int i = 1; i < ROWS; i++ ) {		for( int j = 0; j < COLS; j++ ) {			/* Pay close attention:			 * The first range given in the assignment is [1,100), which			 * is 1-99.  The rest of the ranges require 0-99.  The following			 * line abuses the internal integer values assigned to booleans.			 * On the first iteration, (bool)i will evaluate to 0 giving us			 * the rand() % 98 that we need for the proper sized range.  For			 * every other iteration, it will result in rand() % 99, since 			 * bool(any-non-zero) == 1, therefore 98+1.  It also turns out			 * that the first iteration is the only case where we need a +1			 * to generate the desired range.  This results in the next			 * expression, !i, which will result in an integer value of 1 in only			 * the first case, and a 0 in every other case.			 */			randomArray[i][j] = rand() % (98 + (bool)i) + !i + (i*100);		}	}