From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Random Integers with unequal chance
Date: Tue, 22 May 2012 16:20:07 +0000 (UTC)
Organization: Indiana University
Lines: 14
Message-ID: <jpgebn$gqe$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1337703607 17230 (22 May 2012 16:20:07 GMT)
NNTP-Posting-Date: Tue, 22 May 2012 16:20:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3499294
Xref: comp.soft-sys.matlab:768635

Hi. I am trying to create random integer generator that gives a better chance of generating a lower number.

The chance I am using are based on (0.5)^x

So I would like the generator to have a 50% chance of giving a 1, 25% chance of giving a 2, 12.5% chance of giving a 3 and so on.

I am cutting the generator off at 20.
 So the function
 randi ([1,20],[1,1]);
is what I am starting from. Someone suggested giving each range their own chance of occuring. So I guess I would use an 'If" statement involving randi (1)>=0.5, randi(2)>=0.25....etc.

But I am a bit lost and drabbled on how to go about starting this script. You don't have to make the whole thing I just need help getting started or a direction to go in.