I need to compute a randomly selected digit from a given four digit number. In this question, I use the terminology similar to “digit 3 of the number 7246 is 2” and “digit 1 of the number 7246 is 6”. That is, digit numbers count from the right, starting at 1.
Input variables:
number
is a single four digit number.
Output Variables:
which_digit
holds a random integer between1
and4
usingrandi
digit
holds thewhich_digit
digit ofnumber
.
A sample case is:
>> number = 7246;
>> rand_digit
which_digit = 3
digit = 2