# 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?
###### 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.

Commented:
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
Commented:
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
Commented:
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