Randomizing an array

Results 1 to 3 of 3

Thread: Randomizing an array

  1. #1
    Join Date
    Dec 1969

    Default Randomizing an array

    I am using the command object which calls a stored procedure in Oracle. I read the results into an array and need to display all the array items in random order. I am not sure how to achieve this. My code is as follows: (this code only shows the command object and stored procedure call to Oracle. Last line show where I read the results into an array.)<BR><BR>Set objAnswerCommand = Server.CreateObject("ADODB.Command")<BR>Set objAnswerCommand.ActiveConnection = objTrnConnection<BR> <BR>objAnswerCommand.CommandText = "{Call WWWTRN.Training_List_Pkg.CreateRandomQuestion(?,{r esultset 0, resultset})}"<BR>objAnswerCommand.Parameters.Appen d objAnswerCommand.CreateParameter("numTestID", adNumeric, adParamInput, 10, numTestID)<BR>objAnswerCommand.CommandType = adCmdText<BR>objAnswerCommand.CommandTimeout = 0<BR> <BR>Set objAnswerCommand = objAnswerCommand.Execute()<BR>arrQA = objAnswerCommand.GetRows

  2. #2
    Join Date
    Dec 1969

    Default See if this helps:

    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=89<BR><BR>And the category:<BR>http://www.aspfaqs.com/aspfaqs/ShowCategory.asp?CatID=1

  3. #3
    Join Date
    Dec 1969

    Default Why not just do it in

    your Oracle procedure &#039;CreateRandomQuestion&#039;? <BR><BR>If you are using Oracle 8i, you can use a function called get_hash_value in the dbms_utility package which simply returns a number based on a passed string then you simply order your results on that column.<BR><BR>So you can do something like following adding the date/time to a field:<BR><BR>SELECT DBMS_UTILITY.GET_HASH_VALUE<BR>(TO_CHAR(dbms_utili ty.get_time)&#124&#124MyTable.field1,2,1048576<BR> ) "RANDOM_ORDER", <BR>MyTable.*<BR>FROM MyTable<BR>ORDER BY RANDOM_ORDER<BR><BR>Does that make sense? <BR><BR>A quick note the &#039;2&#039; and &#039;1048576&#039; values are the base and size of the hash table and these are Oracle recommended values.<BR><BR>You can even create this as a view, then if say you only want the first 10 records you can do<BR><BR>select * from myrandomview where rownum &#060; 11<BR><BR>and you&#039;ll get different records each time.<BR><BR>Good luck<BR>Pete<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts