View Full Version : random naming


Hitchcock
09 September 2007, 07:23 PM
I am trying to write a script to randomly name a locator handle. I would like to have a list of names that a proc can reference but i can not think of how do this if any of you can help that would be great. thanks

trancor
09 September 2007, 07:38 PM
Neat idea, not too hard to do. How I'd do it is set up a string array with the names you want, and then simply pull a random number element from that array.

string $locNames[]={"Rabadon", "Shlaboush", "Nogiton", "Goofahob"};
int $randName=rand(0,(size($locNames)));
//Test the code
print $locNames[$randName];

//For the renaming --
rename locatorName $locNames[$randName];



Lets say you want to have multiple objects you have selected that you want them to rename randomly-


string $locNames[]={"Rabadon", "Shlaboush", "Nogiton", "Goofahob"};
string $selected[]=`ls -sl`;
for($i=0; $i<(size($selected)); ++$i){
int $randName=rand(0,(size($locNames)));
rename $selected[$i] $locNames[$randName];
}


Hope you can work with this, good luck on the script.

CGTalk Moderation
09 September 2007, 07:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.


1