randomly order a list

Michael Mays michael_livecode at nayyan.com
Thu May 23 00:07:30 EDT 2013

As I understand the sort command the syntax is something like:
	sort this_group _of_thing by the _text _values_in _this _other_thing 
so what it seems like to me is that Randy is saying
	sort the_lines_in_this_thing by either_1_or_2_or_3
In other words the lines are being sorted by a constant: 1 or 2 or 3. And since lines of a container are being sorted, shouldn't the sort key be some part of each line being sorted?? 

I don't think the sort command is what Randy needs. He needs a shuffle function:

on mouseUp
 put "cat" into line 1 of my_lines
 put "rat" into line 2 of my_lines
 put "dog" into line 3 of my_lines
 put Shuffle_The_Lines(my_lines) into my_shuffled_lines
 put my_shuffled_lines
end mouseUp

function Shuffle_The_Lines some_lines
 repeat with counter = number of lines in some_lines down to 1
    put  (random (counter)) into random_line_number
    put line random_line_number of some_lines into random_line
    put  random_line  into line counter of shuffled_lines
    delete line random_line_number of the_lines
 end repeat
 return shuffled_lines
end Shuffle_The_Lines

On May 23, 2013, at 1:59 AM, Chris Sheffield <cmsheffield at icloud.com> wrote:

> I have a list of three words that I need to be randomly sorted. To start with, the first word is the correct answer to a question. I want to re-order the list so that the correct answer may be the second or third word, and not necessarily the first. How can I do this successfully every time? The docs give an example like this:
> 	sort lines of myVar by random(the number of lines of myVar)
> But this only seems to work successfully one time. After that, the list is always set so the first word is the correct answer. So then I tried randomly setting the randomSeed value, since this value is supposed to affect the random() function and the any keyword, but this didn't seem to make much difference except to change it so either the second or third word is *always* the right answer. I need it to be more mixed up than that.
> So does anyone have a good way to do this?
> Thanks,
> Chris
> --
> Chris Sheffield
> Read Naturally, Inc.
> www.readnaturally.com
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

More information about the use-livecode mailing list