Coldfusion Powerball lottery pick tool
Ever wanted to pick lottery numbers with your own tool? This tool is setup for the powerball. and has set by step explanations.
<!---in coldfusion pick random values is a pain, because if you need five numbers changes are you will get duplicates.--->
<!---We have added some code to deal with that.--->
<!---First we are setting a parameter to create an array called randArray.--->
<cfparam
name="randArray"
type="any"
default="#ArrayNew(1)#" />
<!---I am setting a loop incremental to zero because I need to work with it in my loop. I need five numbers, but first I set it to zero...stay with me.--->
<cfset loopIncremental = 0>
<!---Now we are creating a conditional loop to check to see if the loop is less than five. It is so we are are going to loop and add 1 to the loop incremental until it hits five then stop (see we need five white balls). --->
<cfloop condition="loopIncremental lt 5">
<!---The arrRandRange is the range of values to pick numbers from. In powerball we need 1 through 54.--->
<cfset arrRandRange = randrange(1, 54)>
<!---We are now taking our array we set above int he parameter and change it to a list--->
<cfset randArrayToList = arraytolist(randArray)>
<!---Now we are checking to see if the list has a duplicate value. and setting that to an if statement which goes like this. If the array/list has the number we just randomly picked, we do nothing. If we have a fresh number we append the array and add that value to it.--->
<cfif listfind(randArrayToList, #arrRandRange#)>
<cfelse>
<!---here is where we add the value if the 'condition' is non-duplicate.--->
<cfset ArrayAppend(randArray,"#arrRandRange#")>
<!---we then increment the loop incremental by 1 (see if if it doesn't get added to the array we are still one number short and so we do not set the incriment. Clear as mud?--->
<cfset loopIncremental = #loopIncremental# + 1>
<!---then we exit the if statement--->
</cfif>
<!---next we exit the loop--->
</cfloop>
<cfoutput>
<!---I'm probably doing a usless step here but my basic effort is to sort the array's numbers from lowest to highest and then output the numbers to the screen.--->
<cfset xArrayToList = ArrayToList(randArray)>
<cfset yListSort = listsort(xArrayToList, "numeric")>
#yListSort#
</cfoutput>
<!---And for my last trick I am grabbing one red ball from a range 1 through 50--->
<cfset arrRandRange2 = randrange(1, 50)>
<!---then outputting that value--->
<cfoutput>
#arrRandRange2#
</cfoutput>
Labels: coldfusion, lottery numbers, powerball, random selection
