Results 1 to 15 of 15

Thread: Need help choosing a random option of 2 strings

  1. #1
    Join Date
    Apr 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Need help choosing a random option of 2 strings

    I have a script already and it works. But it only allows you to choose only one option. You can change it to say big, or small. I want it to randomly pick it for me. I have been racking my brain to figure it out. I need to learn to code.

  2. #2
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Simba Code:
    x := Random(2);
       Case x of
        0 : TypeSendEx('Small',true);
        1 : TypeSendEx('Big',true);
      end;

    Is that what you are after?
    Last edited by Justin; 04-28-2012 at 03:10 PM.

    Forum account issues? Please send me a PM

  3. #3
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by [J]ustin View Post
    Simba Code:
    x := Random(2)
       Case x of
        1 : TypeSendEx('Small',true);
        2 : TypeSendEx('Big',true);
      end;
    It's actually supposed to be:
    Simba Code:
    x := Random(2)
       Case x of
        0 : TypeSendEx('Small',true);
        1 : TypeSendEx('Big',true);
      end;

  4. #4
    Join Date
    Apr 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by [J]ustin View Post
    Simba Code:
    x := Random(2)
       Case x of
        1 : TypeSendEx('Small',true);
        2 : TypeSendEx('Big',true);
      end;

    Is that what you are after?
    Looks right. I understand the code is easy to do. I will try it and see if it works.

    [Error] (35:3): is ('=') expected at line 34

  5. #5
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Quote Originally Posted by abu_jwka View Post
    It's actually supposed to be:
    Simba Code:
    x := Random(2)
       Case x of
        0 : TypeSendEx('Small',true);
        1 : TypeSendEx('Big',true);
      end;
    Yep, just noticed it, was about to come back and edit my post!

    Quote Originally Posted by kingofbigmac View Post
    Looks right. I understand the code is easy to do. I will try it and see if it works.

    [Error] (35:3): is ('=') expected at line 34
    Post the highlighted line please

    Forum account issues? Please send me a PM

  6. #6
    Join Date
    Apr 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by [J]ustin View Post
    Yep, just noticed it, was about to come back and edit my post!



    Post the highlighted line please
    x := Random(2)

  7. #7
    Join Date
    Mar 2007
    Posts
    5,125
    Mentioned
    275 Post(s)
    Quoted
    901 Post(s)

    Default

    Quote Originally Posted by kingofbigmac View Post
    x := Random(2)
    Weird...

    Simba Code:
    program new;
    var x : integer;
    begin
    writeln('Start of script');
    x := Random(2);
     Case x of
      0 : writeln('This is 0');
      1 : writeln('This is 1');
     end;
    writeln('End of script');
    end.

    Progress Report:
    Start of script
    This is 1
    End of script
    Successfully executed.
    Compiled successfully in 0 ms.
    Start of script
    This is 0
    End of script
    Successfully executed.


    If you want you can PM (click here) me the script and I will take a look at it.

    Forum account issues? Please send me a PM

  8. #8
    Join Date
    Apr 2007
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    PM sent

  9. #9
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    You don't even need to put the whole x part.
    Simba Code:
    case Random(2) of
    will do that same job.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  10. #10
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by Rich View Post
    You don't even need to put the whole x part.
    Simba Code:
    case Random(2) of
    will do that same job.
    I think using x as a replacement will same some ms though. Not that it makes much of a difference, but certainly a good habit nonetheless.

  11. #11
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Using x:
    Code:
    Compiled successfully in 32 ms.
    Hello
    Successfully executed.
    Not using x:
    Code:
    Compiled successfully in 31 ms.
    Hello
    Successfully executed.
    Using if then else
    Code:
    Compiled successfully in 31 ms.
    Hello
    Successfully executed.
    And to be honest, I don't really see how using unnecessary code is a good habit, but that's just my opinion.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  12. #12
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

  13. #13
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by abu_jwka View Post
    I think using x as a replacement will same some ms though. Not that it makes much of a difference, but certainly a good habit nonetheless.
    No it won't. It will only save a few microseconds if using it in a loop.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  14. #14
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by Daniel View Post
    No it won't. It will only save a few microseconds if using it in a loop.
    Well I was just trying to justify what [J]ustin wrote, I never do this myself

  15. #15
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Simba Code:
    var
      TSA :TStringArray;

    begin
      TSA := ['High', 'Low'];
      WriteLn(TSA[Random(Length(TSA))])
    end.


    ~Home

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
  •