for loop - Roll die and return number of 4's Matlab -


i need write function roll 4-sided die n times , return number of 4's rolled. want use randperm , lop in matlab function. far have:

function [value2] = rolldie( n )  %this function inputs number of times 4-sided die rolled , %returns number of times 2 rolled.  %   n = number of times die rolled  x = ranperm(4);  v = x(1);  count = 0;  v = 2      count = count + 1; end 

i'm not sure if correct begin with, cant figure out how make function run through n times based on input of number of times rolled.

you can create random vector or numbers 1 6 using randi, or random integer generator. code like

 function count = rolldire(n)  % produce n random rolls of 6-sided die rolls = randi(6,1,n);  % count number of times encounter number 4 count = sum(rolls == 4); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -