Results 1 to 7 of 7

Thread: function randomex (need testers)

  1. #1
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    my random function (need testers)

    ok i have made function randomex:
    ( i hope you will understand it)
    SCAR Code:
    {-------/////Script made by\\\\\-------}
    {------(########################)------}
    {------(>>>>>>|Snapy Gapi|<<<<<<)------}
    {------(########################)------}
    {-------\\\\\\\------------/////-------}
    //Function randomex by Snapy Gapi//

    //function randomex://
    //startrange: this is the starting value of the random range//
    //endrange: this is the ending value of the random range//
    //midpoint: this stands betwean startrange and endrange, the most random values will be midpoint//
    //domidpoint: this turns midpoint on or off (true=on, false=off) (if its off then put anything you like in midpoint//

    function randomex(startrange, endrange, midpoint: integer; domidpoint: boolean): integer;

    var
    endrangex, xl: integer;


    begin

      midpoint:=midpoint+1

          if (midpoint<=0) then
            begin
             midpoint:=2
            end;

       if (domidpoint=true) then

        begin

                         repeat

                               begin
                                endrangex:= random(endrange)
                                xl:=(midpoint*2)-endrangex
                                result:= random(endrangex)+(random(xl))
                               end;

                         until (result > startrange) and (result < endrange)


        end else



           begin

                             repeat

                                 begin
                                 endrangex:=random(endrange)
                                 result:=endrangex
                                 end;

                             until (endrangex > startrange) and (endrangex < endrange)

           end;

    end;

    ok this function is similar to random() just that you can set the:

    startrange (start of the random range)

    endrange (end of the random range)

    midpoint (chance of the random value is raising from startrange to midpoint(highest) and falling falling from midpoint to endrange)

    domidpoint (if you set this false the function will skip the midpoint, (and if you set it so just put anything for midpoint value.


    I tested the function and it works fine.
    But if you find any bug in it please tell me and ill try to fix it
    end.

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
       var counters: array [0..100] of integer;

       number,i:integer;

    function randomex(startrange, endrange, midpoint: integer; domidpoint: boolean): integer;

    var
    endrangex, xl: integer;


    begin

      midpoint:=midpoint+1

          if (midpoint<=0) then
            begin
             midpoint:=2
            end;

       if (domidpoint=true) then

        begin

                         repeat

                               begin
                                endrangex:= random(endrange)
                                xl:=(midpoint*2)-endrangex
                                result:= random(endrangex)+(random(xl))
                               end;

                         until (result > startrange) and (result < endrange)


        end else



           begin

                             repeat

                                 begin
                                 endrangex:=random(endrange)
                                 result:=endrangex
                                 end;

                             until (endrangex > startrange) and (endrangex < endrange)

           end;

    end;
    begin
      SetupSRL;
     
      repeat
        number:=randomex(0,100,50,true);
        counters[number]:=counters[number]+1;
        i:=i+1;
        cleardebug;
        writeln(inttostr(i));
      until i=100000;//isfkeydown(12);
      i:=0;
      repeat
        writeln(inttostr(i)+' = '+inttostr(counters[i]));
        i:=i+1;
      until i=100;
    end.

    Run that. Looks good. Now change the mdpt 50 to 30 and run it again.

  3. #3
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    oo thx trying to solve it...

    anyone any ideas?
    end.

  4. #4
    ronny.m.p Guest

    Default

    You changed the mdpt without changeing the end range...

  5. #5
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    The mdpt isn't supposed to be exactly between the start and end. If it was, it wouldn't be in the parameters, it would just be figured out from the start and end during the procedure. Numbers near the mdpt should be more likely to occur. This part is working. However when you do 0 100 30, 60-100 never occur at all (AFAIK from 10k tries).

  6. #6
    ronny.m.p Guest

    Default

    I see...i'll do some more testing...

    Off topic: Boreas do you have any ideas for the pm i sent you and for the thread i started??

  7. #7
    Join Date
    Jan 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for the testing script boreas, i had no idea about how to test it...

    and i added a chance calculator in it, and the report at the end is aligned:

    SCAR Code:
    function randomex(startrange, endrange, midpoint: integer; domidpoint: boolean): integer;
     
    var
    endrangex, xl: integer;
     
     
    begin
     
      midpoint:=midpoint+1
     
          if (midpoint<=0) then
            begin
             midpoint:=2
            end;
     
       if (domidpoint=true) then
     
        begin
     
                         repeat
     
                               begin
                                endrangex:= random(endrange)
                                xl:=(midpoint*2)-endrangex
                                result:= random(endrangex)+(random(xl))
                               end;
     
                         until (result > startrange) and (result < endrange)
     
     
        end else
     
     
     
           begin
     
                             repeat
     
                                 begin
                                 endrangex:=random(endrange)
                                 result:=endrangex
                                 end;
     
                             until (endrangex > startrange) and (endrangex < endrange)
     
           end;
     
    end;
     

    var
       counters: array [0..1000] of integer;
       number,i,chancei,roundchance,lengthi,lengthcounter,lengthroundchance:integer;
       chance: extended;
       ilength,counterlength,roundchancelength: string;

    begin

      repeat
        number:=randomex(0,100,50);
        counters[number]:=counters[number]+1;
        i:=i+1;
      until (isfkeydown(12) and (i>=10000) or (i=1000000000000))
       chancei:=i
       cleardebug;
       writeln('Done ' + inttostr(i) + ' times');
       writeln('REPORT:');
       i:=0;
      repeat
      chance:= counters[i] div chancei
      chance:= chance * 100
      roundchance:= round(chance)
      lengthi:= length(inttostr(i))
      lengthcounter:= length(inttostr(counters[i]))
      lengthroundchance:= length(inttostr(roundchance))
     
      if (lengthroundchance=1) then begin roundchancelength:= '   ' end;
      if (lengthroundchance=2) then begin roundchancelength:= '  ' end;
      if (lengthroundchance>=3) then begin roundchancelength:= ' ' end;
      if (lengthi=1) then begin ilength:= '   ' end;
      if (lengthi=2) then begin ilength:= '  ' end;
      if (lengthi=3) then begin ilength:= ' ' end;
      if (lengthi>=4) then begin ilength:= '' end;
      if (lengthcounter=1) then begin counterlength:= '       ' end;
      if (lengthcounter=2) then begin counterlength:= '      ' end;
      if (lengthcounter=3) then begin counterlength:= '     ' end;
      if (lengthcounter=4) then begin counterlength:= '    ' end;
      if (lengthcounter=5) then begin counterlength:= '   ' end;
      if (lengthcounter=6) then begin counterlength:= '  ' end;
      if (lengthcounter=7) then begin counterlength:= ' ' end;
      if (lengthcounter>=8) then begin counterlength:= '' end;
     
      writeln('Number '+ inttostr(i) + ilength + 'Detected '+inttostr(counters[i]) + counterlength + 'times  ' + '   chance is round: '+ inttostr(roundchance)+'%' + roundchancelength + 'or ' +floattostr(chance)+ '% for exact');
     
     
        i:=i+1;
      until i=100;
    end.



    I will try to put my nose into a math book and then i will try again
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need some testers.
    By Nava2 in forum News and General
    Replies: 6
    Last Post: 09-04-2008, 01:30 AM
  2. need testers
    By ShowerThoughts in forum News and General
    Replies: 0
    Last Post: 09-21-2007, 04:43 PM
  3. Testers
    By monkeyboy_2006 in forum News and General
    Replies: 0
    Last Post: 09-02-2007, 11:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •