Random numbers with double chance for some!

I need to write a procedure that generates 6 unique random numbers from 49. But I want to be able to double the chances of 3 selected number being generated. The first bit is easy using Random but how do i double the chance for the selected numbers?
bennionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

philipleighsCommented:
OK, say your three numbers that you want to double the chance are:

5, 17, 22

Well, instead of looking between 1 and 49, look between 1 and 52.

If you get 50, then change it to 5
If you get 51, then change it to 17
If you get 52, then change it to 22

Cheers,
Phil.
0
kambizCommented:
Assume you want to double the chance of a, b, and c:

Value := Random(49);
if not (Value in [a, b, c]) then
begin
  OtherChance := Random(49);
  if OtherChance in [a, b, c] then
    Value := OtherChance;
end;

0
TheNeilCommented:
Match_Set := [1, 2, 3];
iChance := 2;

iCnt := 0;
REPEAT
  iValue := Random(49);
  IF iValue IN Match_Set
  THEN
    iCnt := iChance + 1
  ELSE
    iCnt := iCnt + 1;
UNTIL (iCnt >= iChance);

This is slightly similar to what Kambiz has done but is more generic allowing you to increase the number of chances that the 'special' numbers have of appearing. It also allows you to create the set a bit more intelligently (just construct the set before you enter the loop). In the above code you'd double the chance of selecting 1, 2, and 3, but by changing the iChance value to 3, you triple it etc.

The Neil
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bennionAuthor Commented:
Thanks everyone all would have worked for me but TheNeil's look to be very flexible. It also solved my next problem which is to inccreae the chance of selection.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.