say I have
alphabet='abcdefghijklmnopqrstuvwxyz'
how do i select a random letter from the alphabet so Guess= random letter from alphabet and once I have selected a random letter from the alphabet, then remove that letter from the alphabet.
Thank you

 채택된 답변

Geoff Hayes
Geoff Hayes 2015년 11월 7일
편집: Geoff Hayes 2015년 11월 7일

0 개 추천

Max - use randperm to generate a random index into your character array. Try the following
alphabet = 'abcdefghijklmnopqrstuvwxyz';
randIdx = randperm(length(alphabet),1); % generate the random index into array
randChar = alphabet(randIdx); % get the random character
alphabet(randIdx) = []; % remove the character
For example, if
randIdx =
14
then
randChar =
n
and
alphabet =
abcdefghijklmopqrstuvwxyz
with the 'n' removed.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

Max
2015년 11월 7일

편집:

2015년 11월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by