I am trying to use various methods of generating a 6 digit random number. They all generate a random number the first time the page is loaded. Every call to it after that produces the exact same numbers. I am trying to reevaluate the page etc on every call to it but that doesn't work. How do I get random numbers every time?
<html>
<head>
<title>Untitled Document</title>
<META http-EQUIV="Expires" CONTENT="Mon, 01 Jan 1970 23:59:59 GMT">
<CFHEADER NAME="Pragma" VALUE="no-cache">
<CFHEADER NAME="Expires" VALUE="Now()">
<CFHEADER NAME="cache-control" VALUE="no-cache, no-store, must-revalidate">
</head>
<body>
<cfset r1 = Randomize(now())>
<cfset r2 = Randomize(now())>
<cfset r3 = Randomize(now())>
<cfset r4 = Randomize(now())>
<cfset r5 = Randomize(now())>
<cfset r6 = Randomize(now())>
<p>RandRange returned:
<cfset r1 = #RandRange(1, 9)#>
<cfset r2 = #RandRange(1, 9)#>
<cfset r3 = #RandRange(1, 9)#>
<cfset r4 = #RandRange(1, 9)#>
<cfset r5 = #RandRange(1, 9)#>
<cfset r6 = #RandRange(1, 9)#>
<cfoutput>#r1#</cfoutput>
<cfoutput>#r2#</cfoutput>
<cfoutput>#r3#</cfoutput>
<cfoutput>#r4#</cfoutput>
<cfoutput>#r5#</cfoutput>
<cfoutput>#r6#</cfoutput>
<cfloop index="Myindex" from="1"
to="6" step="1">
<cfloop index="randomindex"
from="1" to="9" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
Magic number number #Myindex#
is: #RandRange
(1,9)#<br><br>
</cfoutput>
</cfloop>
<cfloop index="Myindex" from="1"
to="1" step="1">
<cfloop index="randomindex"
from="1" to="100000" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
number number #Myindex#
is: #RandRange
(100000,999999)#<br><br>
</cfoutput>
</cfloop>
LAST EXAMPLE
<CFSET r=randomize(now())>
<cfset i = 1>
<!--- just testing randomness --->
<cfloop condition="i lt 11">
The random number is: <cfoutput>#rand()#</cfoutput><BR>
<cfset i = i + 1>
</cfloop>
<CFSET r=RandRange(100000,999999)>
<cfoutput>#r#</cfoutput>
GENERATOR
<cfscript>
//Initialize variables
variables.itemCount = 1;
variables.bannerlist = '';
variables.retrieveIDList = '';
variables.retrieved = 6;// how many random numbers do you want to select
// Set the Min and Max Variables for the Banners
variables.begin = 1; // begin range
variables.end = 9; // end range
//Loop until variables.retrieved unique numbers have been randomly chosen
while( Variables.ItemCount LTE Variables.Retrieved ){
//Pick a random ID number based on the minimum and maximum ID
Variables.RandomID = RandRange(Variables.begin, Variables.end);
//If the new ID is not already in the results list, add it
if( ListFind(Variables.RetrieveIDList, Variables.RandomID) EQ 0 ){
//A random ID has been found that is in the list and is not in the results list...increment the counter
Variables.ItemCount = Variables.ItemCount + 1;
Variables.RetrieveIDList = listAppend(Variables.RetrieveIDList, Variables.RandomID);
}
}
</cfscript>
<cfoutput>=== #Variables.RetrieveIDList# ===</cfoutput>
RANDOM 6 digit CHARACTER PASSWORD
<cfset characterList = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z">
<!--- create the random password --->
<CFSET pwd="">
<CFLOOP FROM="1" TO="6" INDEX="i">
<CFSET randNum = RandRange(1,ListLen(characterList))>
<CFSET randLetter = ListGetAt(characterList, #randNum#)>
<CFSET pwd = pwd & randLetter>
</CFLOOP>
<cfoutput>#pwd#</cfoutput>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<META http-EQUIV="Expires" CONTENT="Mon, 01 Jan 1970 23:59:59 GMT">
<CFHEADER NAME="Pragma" VALUE="no-cache">
<CFHEADER NAME="Expires" VALUE="Now()">
<CFHEADER NAME="cache-control" VALUE="no-cache, no-store, must-revalidate">
</head>
<body>
<cfset r1 = Randomize(now())>
<cfset r2 = Randomize(now())>
<cfset r3 = Randomize(now())>
<cfset r4 = Randomize(now())>
<cfset r5 = Randomize(now())>
<cfset r6 = Randomize(now())>
<p>RandRange returned:
<cfset r1 = #RandRange(1, 9)#>
<cfset r2 = #RandRange(1, 9)#>
<cfset r3 = #RandRange(1, 9)#>
<cfset r4 = #RandRange(1, 9)#>
<cfset r5 = #RandRange(1, 9)#>
<cfset r6 = #RandRange(1, 9)#>
<cfoutput>#r1#</cfoutput>
<cfoutput>#r2#</cfoutput>
<cfoutput>#r3#</cfoutput>
<cfoutput>#r4#</cfoutput>
<cfoutput>#r5#</cfoutput>
<cfoutput>#r6#</cfoutput>
<cfloop index="Myindex" from="1"
to="6" step="1">
<cfloop index="randomindex"
from="1" to="9" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
Magic number number #Myindex#
is: #RandRange
(1,9)#<br><br>
</cfoutput>
</cfloop>
<cfloop index="Myindex" from="1"
to="1" step="1">
<cfloop index="randomindex"
from="1" to="100000" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
number number #Myindex#
is: #RandRange
(100000,999999)#<br><br>
</cfoutput>
</cfloop>
LAST EXAMPLE
<CFSET r=randomize(now())>
<cfset i = 1>
<!--- just testing randomness --->
<cfloop condition="i lt 11">
The random number is: <cfoutput>#rand()#</cfoutput><BR>
<cfset i = i + 1>
</cfloop>
<CFSET r=RandRange(100000,999999)>
<cfoutput>#r#</cfoutput>
GENERATOR
<cfscript>
//Initialize variables
variables.itemCount = 1;
variables.bannerlist = '';
variables.retrieveIDList = '';
variables.retrieved = 6;// how many random numbers do you want to select
// Set the Min and Max Variables for the Banners
variables.begin = 1; // begin range
variables.end = 9; // end range
//Loop until variables.retrieved unique numbers have been randomly chosen
while( Variables.ItemCount LTE Variables.Retrieved ){
//Pick a random ID number based on the minimum and maximum ID
Variables.RandomID = RandRange(Variables.begin, Variables.end);
//If the new ID is not already in the results list, add it
if( ListFind(Variables.RetrieveIDList, Variables.RandomID) EQ 0 ){
//A random ID has been found that is in the list and is not in the results list...increment the counter
Variables.ItemCount = Variables.ItemCount + 1;
Variables.RetrieveIDList = listAppend(Variables.RetrieveIDList, Variables.RandomID);
}
}
</cfscript>
<cfoutput>=== #Variables.RetrieveIDList# ===</cfoutput>
RANDOM 6 digit CHARACTER PASSWORD
<cfset characterList = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z">
<!--- create the random password --->
<CFSET pwd="">
<CFLOOP FROM="1" TO="6" INDEX="i">
<CFSET randNum = RandRange(1,ListLen(characterList))>
<CFSET randLetter = ListGetAt(characterList, #randNum#)>
<CFSET pwd = pwd & randLetter>
</CFLOOP>
<cfoutput>#pwd#</cfoutput>
</body>
</html>