Randomization

Like flipping a coin, or throwing a dice.


Randomization

Like flipping a coin, or throwing a dice.

Randomization is the process of making something random. Randomization is not haphazard; instead, a random process is a sequence of random variables describing a process whose outcomes do not follow a deterministic pattern, but follow an evolution described by probability distributions.

Code

Flipping a coin

  // flipping a coin (pick a color)
  if (random(1, 10) > 5) {
    fill('white');
  } else {
    fill('blue');
  }
  // flipping a coin (pick a color)
  if (random(1, 10) > 5) {
    fill('white');
  } else {
    fill('blue');
  }

Throwing dice

  // throwing dice (pick a shape)
  const dice = int(floor(random(1, 7)));
  switch (dice) {
    case 1:
      letterM(x, y);
      break;
    case 2:
      letterO(x, y);
      break;
    case 3:
      letterN(x, y);
      break;
    case 4:
      letterOo(x, y);
      break;
    default:
    // silence, silencio
  }
  // throwing dice (pick a shape)
  const dice = int(floor(random(1, 7)));
  switch (dice) {
    case 1:
      letterM(x, y);
      break;
    case 2:
      letterO(x, y);
      break;
    case 3:
      letterN(x, y);
      break;
    case 4:
      letterOo(x, y);
      break;
    default:
    // silence, silencio
  }