%%% Script to randomly select five students from the class
clear; close all

%% Data

% Define the number of lucky students
n_lucky = 5;

% Define student data as a cell-array
students = {    ...
  'David L',    ...
  'Claire P',   ...
  'Michael N',  ...
  'Lee S',      ...
  'Ryan H',     ...
  'Scott C',    ...
  'Haitham A',  ...
  'Sirak C',    ...
  'Jamie W',    ...
  'Lance R',    ...
  'Jared R',    ...
  'Mitchell H', ...
  'Andrew Q'    ...
};

% Save the number of students as a variable
n_students = length(students);

% Seed the random number generator ... 
% this allows us to all see the same results (but it's still random)
rng(2349578090) % just keyboard-mashed that integer

%% Selection

% Select by looping through n_lucky times
students_pool = students;
stop_flag = 0;
students_lucky = cell(n_lucky,1);
for i = 1:n_lucky
  % generate a random number between 1 and n_students
  rand_index = ceil(rand(1,1)*length(students_pool)); % index of lucky student
  students_lucky{i} = students_pool{rand_index}; % add lucky student
  disp(['lucky student #',num2str(i),': ',students_lucky{i}])
  % delete the lucky student from the pool
  indices = 1:length(students_pool); % all indices
  indices(rand_index) = []; % delete the lucky index
  students_pool = students_pool(indices); % filtered pool
end