Results 1 to 4 of 4

Thread: RandomRange(Extended, Extended);

  1. #1
    Join Date
    Jan 2010
    Posts
    1,414
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default RandomRange(Extended, Extended);

    I wish to do something as the title says. I want to be able to generate a random range of an extended value, say like this:
    Simba Code:
    function HandleExtended: Extended;
    begin
      Result := RandomRange(0.75, 1.00);
    end;

    Is there any way that I am not seeing that will allow me to generate a random range between extended values?

    Thank you very much in advance for any guidance for this matter, I really appreciate it!

  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Well for your specific example you can just do extended_var := RandomRange(75, 100) / 100.0;. And any other example that should be fine (scaled according to the numbers and what not).

  3. #3
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    I've created something like that for my RangeGuilder, not the best but it works well.

    Simba Code:
    function RandomRangeEx(rFrom, rTo : Variant) : Variant;
    var
      r  : Variant;
    begin
      r := RandomRange(Floor(rFrom), Ceil(rTo));
      r := r + RandomE;

      repeat
        begin
          if r <= rFrom then
            r := r + RandomE
          else if r >= rTo then
            r := r - RandomE;
        end;
      until ((r >= rFrom) and (r <= rTo))

      r := (Trunc(r * 100) / 100.00)

      Result := r;
    end;
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


  4. #4
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Simba Code:
    function RandomRangeE(AFrom, ATo: Extended): Extended;
    begin
      Result := RandomE * (ATo - AFrom) + AFrom;
    end;

    Pretty much how Random and RandomRange work, except for floats
    Hup Holland Hup!

Thread Information

Users Browsing this Thread

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

Posting Permissions

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