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:
numberis a single four digit number.
Output Variables:
which_digitholds a random integer between1and4usingrandidigitholds thewhich_digitdigit ofnumber.
A sample case is:
>> number = 7246;
>> rand_digit
which_digit = 3
digit = 2