Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Pascal Programmin help wanted

Options
  • 19-11-2002 12:54pm
    #1
    Registered Users Posts: 9,443 ✭✭✭


    i am trying to do this program based on a 46 number lotto. its the same as the normal lotto.

    The one problem is that when i run it as is its picks the same numbers evry time its runs.

    And if i add in the randomize; function it runs picks the same winning and quick pick numbers.

    Please help.

    program lottonumbers (input,output);
    uses wincrt;
    type lottoarray = array[1..6] of integer;
    type bonusarray = array[1..1] of integer;
    var usernumbers,quick,winning:lottoarray;
    var bonus:bonusarray;
    var i,k,choice,loop,check,count,j:integer;


    procedure ownnumbers;
    begin
    for i :=1 to 6 do
    begin
    writeln('Please enter your number ',i);
    readln(usernumbers);
    end;
    end;


    procedure fill(var winning:lottoarray);
    begin

    for loop :=1 to 6 do
    begin
    winning[loop]:=random(45)+1;
    write(winning[loop],',');
    end;
    writeln;
    end;

    procedure bonusnum (var bonus:bonusarray);
    begin

    begin
    bonus[1]:=random(45)+1;
    writeln('The Bonus number is ',bonus[1]);
    end;
    end;
    procedure lottochoice;
    begin
    repeat

    writeln('Please pick a lotto type');
    writeln('1. Play your own 6 numbers');
    writeln('2. Play a quick pick');
    readln(choice);
    until (choice =1) or (choice =2);

    if choice = 1 then
    begin
    ownnumbers;
    end
    else
    begin
    Writeln ('Your quickpick numbers are');
    end;
    end;


    procedure checking(numbers1,numbers2:lottoarray);
    begin
    for i:= 1 to 6 do
    begin
    for j:= 1 to 6 do
    begin
    if numbers1= numbers2[j] then
    count:=count+1;
    end;
    if numbers1 = bonus[1] then
    count := count + 10;
    end;
    writeln (count);
    end;


    procedure results;
    begin
    case count of
    1: Writeln('You have won nothing');
    2: Writeln('You have won nothin');
    3: Writeln('You have won nothing');
    4: Writeln('You have won $200');
    5: Writeln('You have won $1,000');
    6: Writeln('You have won $1,000,000');
    13: Writeln('You have won $100');
    14: Writeln('You have won $500');
    15: Writeln('You have won $15,000');
    else Writeln('You have won nothing')
    end;


    end;


    begin (*Main Program*)
    lottochoice;
    fill(quick);
    fill(winning);
    bonusnum(bonus);
    checking(usernumbers,winning);
    checking(quick,winning);
    results;
    end.


Comments

  • Registered Users Posts: 6,240 ✭✭✭hussey


    I dont know pascal, but :

    is there anyway of saying, next random number instead of
    ' bonus[1]:=random(45)+1;'

    do you have to supply a seed for the random number?


  • Registered Users Posts: 2,808 ✭✭✭Ste.phen


    I don't remember much pascal (what a differnece a year makes!),
    but i think there was a way to use the time as a seed.
    You need to use windos as well as wincrt, and i forget how to specify what seed to use, but there's a time function built into windos that's useful.


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Me thinks, perhaps you should be looking at a way to seed your pseudo random number generator.


  • Registered Users Posts: 9,443 ✭✭✭irishgeo


    Whats this seed business. Can i have an example of it


  • Registered Users Posts: 2,781 ✭✭✭amen


    whenever a random number generator is called it always generates the same random numbers in the same order

    in order to prevent this the generator is normally passed some unique value which it uses as a "seed" for generating random numbers

    the current date/time is normally used as a seed


  • Advertisement
  • Registered Users Posts: 1,391 ✭✭✭fatherdougalmag


    irishgeo, the Randomize procedure initialises the random number generator. You say that you've already tried Randomize in your app and that doesn't seem to help.

    What Pascal implementation are you using? Turbo Pascal? Delphi? I'll have a quick look if I can get my hands on a suitable compiler/IDE.


  • Registered Users Posts: 1,391 ✭✭✭fatherdougalmag


    irishgeo,
    I managed to find Turbo Pascal 5.5 on the Borland website so I used that. Boy does that take me back ...

    Anyway.

    I believe the problem is that you are calling Randomize at the wrong place. You should only call it once per program run (and not in your 'fill' procedure). In other words, put it after the main Begin in your app. You'll then get random numbers to your heart's content.

    Hope that helps.


  • Registered Users Posts: 9,443 ✭✭✭irishgeo


    thanks for all the help. I did figure it out that i was calling the randomize feature too many times and it now sits happily in the main program code.


  • Registered Users Posts: 15,944 ✭✭✭✭Villain


    Originally posted by irishgeo
    thanks for all the help. I did figure it out that i was calling the randomize feature too many times and it now sits happily in the main program code.

    Did you get it to work then?? if so could i have a look at the code, I'm trying to implement something similar but in C, I'm trying to use the computer clock as my seed. Thanks


Advertisement