I know i can use:
random number from 1 to 15
but how can i do something like:
random item from mylist
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)
I know i can use:
random number from 1 to 15
but how can i do something like:
random item from mylist
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)
something like this perhaps?
set the_values_list to {"value1", "value2", "value3", "value4"} as list --your initial list values
set the list_count to the count of the_values_list --gets number of items in list
set pick to random number from 1 to list_count --has it choose a random item
set generated_choice to item pick of the_values_list as string --sets the generated item as the choice
return generated_choice --displays the choice
Hi,
You can use ‘some’:
set l to {1,2,3}
some item of l
gl,
AppleScript has it covered:
set mylist to {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
repeat
display dialog "A random pick is " & some item of mylist & return & return & "Use the 'Cancel' button to get out"
end repeat
Oops - Kel beat me to it. :rolleyes:
very true, forgot about that, thanks Kel and Adam
thank you
Browser: Firefox 2.0
Operating System: Mac OS X (10.4)
So to combine the two if you want to use text instead of just numbers.
set mylist to {"Bob", "Brian", "Mark", "Joshua", "Sarah", "George"} as list
repeat
display dialog "A random pick is " & some item of mylist & return & return & "Use the 'Cancel' button to get out"
end repeat
or if you have Quicksilver installed this is a little more exciting.
set mylist to {"Bob", "Brian", "Mark", "Joshua", "Sarah", "George"} as list
tell application "Quicksilver" to show large type "" & some item of mylist & " has been chosen!"
Hi
this is for any size list in sheet1,gets random name from list and stats and copies to sheet2
tell application "Microsoft Excel"
launch
set destRange to range "A1" of sheet "Sheet2" of active workbook
activate object worksheet "Sheet1"
set columnToTest to range "a:a" of active sheet -- list column
set cellCount to count of cells of columnToTest
set usedRanges to used range of worksheet object of columnToTest
set rowsCount to first row index of (get end cell cellCount of columnToTest direction toward the top)
set randomNumber to (random number from 1 to rowsCount) as integer
set gotNumber1 to randomNumber
try
set range1 to range ("a" & gotNumber1)
set range2 to range ("p" & gotNumber1) --b to p data for list
set range3 to (get address of range1) & ":" & (get address of range2)
copy range range range3 destination destRange
end try
end tell
hope this helps
bills