How to create a random number that is a percent of each element in a vector

4 ビュー (過去 30 日間)
Brian Peoples
Brian Peoples 2019 年 2 月 25 日
編集済み: Kevin Phung 2019 年 2 月 25 日
Hello--
I was wondering if anybody could solve this simple roulette indexing/random number question i've been struggling with for a long time. In the for loop I need to create a variable Bet that is a random number that is between 2-12% of each value in row 1 of RoulettePlayers. I commented where I need to include this. Any help is appreciated I've been trying to figure this out for hours.
%Roulette
RouletteRounds = 10 %number of rounds
RoulettePlayers = zeros(RouletteRounds+1,RouletteRounds);
initial_intt = randi([5000,25000],1,10); %randomly generates initial integer value for in pocket $
RoulettePlayers(1,:) = initial_int %makes row 1 of RouletteRounds equal to in pocket cash
BetType = zeros(3,10); %ignore this
for l = 1:RouletteRounds
Bet = randi(1,RoulettePlayers) %<- here i need to create a random number that is between 2-12% of the inidivduals in pocket cash (so row 1 of Roulette Players)
end

採用された回答

Kevin Phung
Kevin Phung 2019 年 2 月 25 日
編集済み: Kevin Phung 2019 年 2 月 25 日
here's a small example:
a = [100 200 300 400 500; 600 700 800 900 1000]
bet = [];
for i = 1:size(a,2) %for the number of columns,
%append a value from 2-12% for each element in the first row
bet(end+1) = randi([.02*a(1,i) .12*a(1,i)]); %randi generates an random integer from [min max]
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by