Chapter 14. Pick a Card, Any Card

Have you ever had someone perform a card trick and ask you to pick a card from the deck? There are 52 cards in a standard deck (the two jokers don't count), and if it's been properly shuffled, you should be able to pick a random card from the deck.

It's the same with rolling a pair of dice. Each die has the potential to roll a number from one to six. When you roll a normal pair of dice, the numbers that appear are random. The odds of rolling a two on one die are the same as rolling a six; they all have the same likelihood of appearing. What allows this to occur is simple randomness.

Your robots also have the ability to generate random numbers. You might want to build a robot that can roll a virtual set of dice or ...

Get Lego Mindstorms NXT-G Programming Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.