PDA

View Full Version : simple selection


Minael2008
01-31-2009, 10:59 PM
Hello I have 3054 objects(pcube05-pcube2058), and i need to randomly select 2138 of them.
I need the objects randomly selected so that they are scattered about.

i know i could do this in MEL, but i am unable to get through the syntax.
Could someone shoot me the code. Would be greatly appreciated. i just need to finish my assigment. Following is a description of my school assignment:

I have boxes in shape of a world map. I need to depict .7 percent of the world drunk. i chose to use the boxes, and have .7 percent (2138) lit up, then i will animate them to shape a new country (boozekistan) then gotta do some other statistics to do my visual data assignment.

If you help me with this section, and in the event I win ("The Back of the Napkin: Solving Problems and Selling Ideas with Pictures (Hardcover)" I will send you the book after i finish reading it. I believe i have a good chance as long as i present this assignment well, and the class votes me winner. If i could just get the code to select only 2138 out of the 3054 objects randomly. I keep losing count clicking, and it doesn't seem randomly enough when i do it manually. plus my computer is sluggish when i move to click another simple box. ugh. If you need any more information, feel free to inquire. If i don't win, I will buy you the book.

dbiggs
02-01-2009, 05:26 AM
0.7% of 3054 is 21.38, not 2138.

that might e easier to select without losing count :)

ewerybody
02-01-2009, 03:52 PM
{
int $all = 3054;
int $max = 2138;

int $randomNumberArray[];
int $count = 0;

int $rand;
for ($i = 1; $i <= $max; $i++)
{
$rand = rand(1,$all);
while(isInIntArray($rand,$randomNumberArray))
$rand = rand(1,$all);

$randomNumberArray[$count++] = $rand;
}

for ($i = 0; $i < $count; $i++)
print (($i + 1) + ": " + $randomNumberArray[$i] + "\n");
}

proc int isInIntArray(int $search, int $array[])
{
for ($item in $array)
if ($item == $search)
return 1;

return 0;
}

quite brute force but just now I couldn't think of another solution for it.

create random number array
loop your wanted count of random numbers from all cubes
create a random int from 1 to "number of all cubes"
while random int is not in random number array create new random int
write int to the random number array
print all ints from the array (or do what you want with it)
printing costs some time.. but selection would do as well.
have phun ;]

Minael2008
02-01-2009, 05:14 PM
note: sorry for the terrible topic name. absent mindedly titled it and sent it off to the printing press: simple selection was a horrid title.

Thanks for the replies. i am using 3054 * .7 to get percentage. It is probably the wrong formula though.
thanks dbiggs.



ewerybody: thanks I will use this code, and I will send you the book. PMing you now. Thanks for your time, and much appreciated!

CGTalk Moderation
02-01-2009, 05:14 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.