Getting MATLAB to randomize a vector of characters

Alright, so I am preparing some code for a friend, who is going to be managing an assassins game. This requires a group of names be randomized. I figured that MATLAB can randomize the list of names. The problem: I can't quite get the randomization to happen.
I have attached what code I have. It works until the randomization. Any help will be appreciated. Thank you!
%This program randomizes the names entered into it so that all effects of
%humans (bias, changing the order, ect.) can be removed from the
%randomization process.
clear, clc %clearing memory
n = 0; count = 0; y = 0; v = 0; w = 0; %establishing variables
display('This program randomizes names for an assassins game.')
n = input('Please put the name of the first participant: ','s'); %the name of first participant, expecting text
count = 1; %running count for how many people in game
v = [n]; %creating vector to contain names
y = input('Would you like to enter more participants, Y or N? ','s'); %asking for more participants
while y == 'Y' %maintaining the loop until the user has no more names
n = input('Please put the name of the next participant: ','s');
v = [v n]; %builds a vector out of the names
count = count + 1; %counts the number of participants
y = input('Would you like to enter more participants, Y or N? ','s'); %asks if there are more participants
end
w = rand(v); %randomozes the names in the vector
display(w) %display the new, randomized vector

 Accepted Answer

Hi Evan, You can format your code to make it easier to read.
If you have the person enter the names in a cell array:
Names = {'Steve','John','Paul','Evan'};
You can then use randperm:
indices = randperm(length(Names));
NewOrder = Names(indices)

More Answers (0)

Categories

Find more on Conway's Game of Life in Help Center and File Exchange

Asked:

on 19 Sep 2011

Community Treasure Hunt

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

Start Hunting!