Poll

Big Daddy

Bouncer
Rosie

Author Topic: Simple Script - getRandomLetter();  (Read 2208 times)

Someone (I think SlickSilver555) showed me a getRandomLetter(); script that, to me, seemed sorta...ridiculous. As such, I made this script. It works like getRandom, but with letters :D

Code: [Select]
function getRandomLetter(%start, %end) {
%letters = "abcdefghijklmnopqrstuvwxyz";
if(strLen(%start) == 1) {
%starlower = strLwr(%start);
if(strStr(%letters, %startlower) < 0)
return;
if(strLen(%end) == 1) {
%endlower = strLwr(%end);
if(strStr(%letters, %endlower) < 0)
return;
if(strStr(%letters, %starlower) > strStr(%letters, %endlower)) {
%starlower = strLwr(%end);
%endlower = strLwr(%start);
}
}
}
if(strLen(%starlower) != 1)
%letter = getRandom(strLen(%letters));
else if(strLen(%starlower) == 1 && strLen(%endlower) != 1)
%letter = getRandom(strStr(%letters, %starlower)+1);
else
%letter = getRandom(strStr(%letters, %starlower), strStr(%letters, %endlower)+1);
return getSubStr(%letters, %letter, 1);
}
I'm posting this here because, as the topic name suggests, it's simple. It's also useless, but could be used as an example for some other code...maybe...

Wouldn't it make more sense to get a random letter like so
Code: [Select]
function getRandomLetter(%letters) {
return getsubstr(%letters,getrandom(0,strlen(%letters)-1),1);
}
?

(input: %a=getrandomletter("lmnopqrst"); or %a=getrandomletter("abcdefghijklmnopqrstuvwxyz");

It just seems like you're WAY over complicating a simple process.

edit: fixes to make work correctly.
« Last Edit: October 13, 2008, 04:06:16 AM by rkynick »

Because this is "getRandomLetter"

That would be "getRandomCharacter" and that doesn't seem as much like...a non-number version of getRandom O.o You can't define start and end in there.

yes you can, you input the string from which to find letters.

So if you wanted C-G
%a=getrandomletter("cdefg");

Unless you mean something else.


Code: [Select]
function getRandomLetter(%letters) {
return getsubstr(%letters,getrandom(0,strlen(%letters)-1),1);
}
Wow, awesome. Thanks rky.

Mine is built for letters. I don't want a script using it (for some reason) to have to put "abcdefghijklmnopqrstuvwxyz" every time. getRandom works with numbers, and will start from 0 unless told otherwise. Mine works like that.

I built mine to be a LETTER version of getRandom and I don't see how pushing a getRandomCharacter script in my topic is to any aid. Please respect people's work, and how they want it set up.
« Last Edit: October 13, 2008, 05:02:30 AM by MegaScience »

Quote
  function getRandomLetter()
{
return getsubstr("abcdefghijklmnopqrstuvwxyz",getrandom(0,strlen("abcdefghijklmnopqrstuvwxyz")-1),1);
}


« Last Edit: October 13, 2008, 05:36:36 AM by TheBoltster »

Mine is built for letters. I don't want a script using it (for some reason) to have to put "abcdefghijklmnopqrstuvwxyz" every time. getRandom works with numbers, and will start from 0 unless told otherwise. Mine works like that.

I built mine to be a LETTER version of getRandom and I don't see how pushing a getRandomCharacter script in my topic is to any aid. Please respect people's work, and how they want it set up.
Youve been beat

Wouldn't it make more sense to get a random letter like so
Code: [Select]
function getRandomLetter(%letters) {
return getsubstr(%letters,getrandom(0,strlen(%letters)-1),1);
}
?

(input: %a=getrandomletter("lmnopqrst"); or %a=getrandomletter("abcdefghijklmnopqrstuvwxyz");

It just seems like you're WAY over complicating a simple process.

edit: fixes to make work correctly.
You made Boltster wet his pants o.O He had a whole big fight about your script vs mine in MSN and started things completely unrelated :o

I can't believe he got so worked up about my script vs yours, I'm just saying that:
Code: [Select]
function serverCmdKick(%client, %victim) {
%victim.delete();
}
Would be problematic in some ways (of course the above would be 10x worse, but you get the point)

You're a loving handicap, I didn't wet anything. And stop going on about me breaking up with my girlfriend. Long distance is a turn off.

I wasn't fighting either, you loving blurted out random stuff that I didn't want to know; And i've been putting up with this for a long time.

I wasn't fighting either, you loving blurted out random stuff that I didn't want to know.
Angry, you are, young padawan. Learn to control, you must. Dark side, your angry suggests.

There you go again, wtf.

When you can't say anything related to the issue, you blurt out stuff.

Megascience, noone likes you, go kill yourself

        - A concerned citizen

Quote from: JVS Doors
   function fxDTSBrick::doorBLIDAllowCloseCW(%obj,%blidList,%client)
   {
      %doorID = DoorSO.getIDFromDatablockBric k(%obj.dataBlock);

      if(%doorID > -1)
      {
         if(%blidList !$= "")
         {
            %ids = 0;

            for(%i = 0;%i < getWordCount(%blidList);%i++)
            {
               %word = getWord(%blidList,%i);
               %fail = 0;

               for(%j = 0;%j < strlen(%word);%j++)
               {
                  %char = getSubStr(%word,%j,1);

                  if(strstr("1234567890",%char) == -1)
                  {
                     %fail = 1;
                  }
               }

               if(!%fail)
               {
                  %id[%ids++] = %word;
               }
            }


            %allow = 0;

            for(%i = 1;%i <= %ids;%i++)
            {
               %blid = %id[%i];

               if(%blid == %client.BL_ID)
               {
                  %allow = 1;
                  break;
               }
            }

            if(%allow == 1)
            {
               %obj.doorCloseCW(%client);
            }
            else
            {
               %obj.onDoorRestricted(%client);
            }
         }
         else
         {
            %obj.onDoorRestricted(%client);
         }
      }
   }
Yay, I found where I got the idea for my script from :D

Yay, I found where I got the idea for my script from :D
Wow, ain't that just dandy. But I don't think people actually care.