Just to add to Robert's post on MySql you can use:

SELECT * FROM tbl_name ORDER BY RAND();

(combine with Limit for big tables/resultsets)




> From: [email protected]
> To: [email protected]
> Subject: RE: TeraScript-Talk: Randomise
> Date: Fri, 9 Mar 2012 10:26:51 -0500
>
> Wayne,
>
> There is no high level function to accomplish your task in one tag.
>
> Most SQL databases support the ability to:
>
>       SELECT * FROM table ORDER BY NEWID()
>
>       Or in some cases
>
>       SELECT * FROM table ORDER BY UUID()
>
> The point being that SQL assigned IDs/UUIDs are themselves a rather random 
> collection of numbers and letters and when sorted create a fairly random 
> result.
>
> TeraScript 6.1 now has @UUID, so you could create a UUID for each row and 
> then sort on that value all in TS if you wanted to. Creating a hash on some 
> piece of data has the similar effect of creating a random (but repeatable) 
> value.
>
> Your way of using and then deleting a random row from the array would also be 
> effective and may give you certain controls - like knowing the state of what 
> rows the user has/has not seen.
>
> Requests for something like this are rare, and it's not on my list to add it 
> to the product, but if users want to reply to this email reinforcing the 
> request, then I'll consider it. I would likely add it as a third "direction" 
> to the @SORT function, that way someone could @SORT COLS="1 ASC,RND" - which 
> would sort the array on column one, but then randomize rows within those 
> subsets. This would actually be a fairly unique and powerful function.
>
> Robert
>
> -----Original Message-----
> From: Wayne Irvine [mailto:[email protected]]
> Sent: Friday, March 09, 2012 2:54 AM
> To: [email protected]
> Subject: TeraScript-Talk: Randomise
>
> Is there any simple way to randomise the row order of an array?
>
> I have a bunch of records of image names and ROWIDs I want to use in a 
> slideshow and I'd like them to appear in order, selected at random once.
>
> I realise I could use the @RANDOM function with a HIGH of @NUMROWS, grab that 
> record, @DELROW from existing array and @ADDROW to a new array and do that 
> recursively until I'd been through the whole array but thought there might be 
> a function for that already:
>
> <@RANDOMISE ARRAY=myarray>
>
> or
>
> <@SORT ARRAY=myarray ROWS="* RAND">
>
> Wayne Irvine
>
> ----------------------------------------
>
> To unsubscribe from this list, please send an email to 
> [email protected] with "unsubscribe terascript-talk" in the body.
>
>
>
> ----------------------------------------
>
> To unsubscribe from this list, please send an email to 
> [email protected] with "unsubscribe terascript-talk" in the body.
>


----------------------------------------

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe terascript-talk" in the body.

Reply via email to