School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,406 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,598 people online right now. Registration is fast and FREE... Join Now!




Selecting a Random Value from a List

 

Selecting a Random Value from a List

iamjesus1342027

8 May, 2009 - 08:23 AM
Post #1

New D.I.C Head
*

Joined: 31 Mar, 2009
Posts: 41

hey all. i am looking to select a random value from a list. here is the code that i have right now but it doesnt seem to be working. i am not getting any errors but the value is not being passed into the variable reportName. let me know if you have any ideas. thanks!!

CODE

<cfset lstReport=& #34;BioDraftReport,CacheDraftReport,CaseFileDraftReport,ChemicalDraftReport,DTKD
raftReport,DetonatorDraftReport,ElectronicDraftReport,IDFDraftReport,IEDDraftRep
ort,MFTERDraftReport">
<cfset objRandomReport=ArrayNew(1)>
<cfloop index="strReport" list="#lstReport#" delimiters=",">
     <cfset temp=ArrayAppend(objRandomReport[name],#lstReport#)>             
     <cfset temp2=ArrayAppend(objRandomReport[strReport],RandRange(1,100))>
</cfloop>
<cfset newArray=ArraySort(objRandomReport[strReport],"numeric","ASC")>
<cfset reportName=#newArray[1]#>


User is offlineProfile CardPM
+Quote Post


simplico

RE: Selecting A Random Value From A List

9 May, 2009 - 04:37 AM
Post #2

New D.I.C Head
*

Joined: 9 May, 2009
Posts: 4

Is this what you are trying to do?

<cfset lstReport= & quot;BioDraftReport,CacheDraftReport,CaseFileDraftReport,ChemicalDraftReport,DTK
DraftReport,DetonatorDraftReport,ElectronicDraftReport,IDFDraftReport,IEDDraftRe
port,MFTERDraftReport">

<cfset objRandomReport=ArrayNew(1)>

<cfset objRandomReport=ListToArray(lstReport)>

<cfset ArraySort(objRandomReport,"textnocase","ASC")>

<!--- random number b/n 1 and length of list/array --->
<cfset reportName=objRandomReport[RandRange(1,ArrayLen(objRandomReport))]>

<cfoutput>#reportName#</cfoutput>

User is offlineProfile CardPM
+Quote Post

iamjesus1342027

RE: Selecting A Random Value From A List

11 May, 2009 - 06:14 AM
Post #3

New D.I.C Head
*

Joined: 31 Mar, 2009
Posts: 41

thanks that was perfect!!




QUOTE(simplico @ 9 May, 2009 - 04:37 AM) *

Is this what you are trying to do?

<cfset lstReport= & quot;BioDraftReport,CacheDraftReport,CaseFileDraftReport,ChemicalDraftReport,DTK
DraftReport,DetonatorDraftReport,ElectronicDraftReport,IDFDraftReport,IEDDraftRe
port,MFTERDraftReport">

<cfset objRandomReport=ArrayNew(1)>

<cfset objRandomReport=ListToArray(lstReport)>

<cfset ArraySort(objRandomReport,"textnocase","ASC")>

<!--- random number b/n 1 and length of list/array --->
<cfset reportName=objRandomReport[RandRange(1,ArrayLen(objRandomReport))]>

<cfoutput>#reportName#</cfoutput>




User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:43PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month