Closed Thread Icon

Preserved Topic: ASP - getting random numbers (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21052" title="Pages that link to Preserved Topic: ASP - getting random numbers (Page 1 of 1)" rel="nofollow" >Preserved Topic: ASP - getting random numbers <span class="small">(Page 1 of 1)</span>\

 
ZOX
Bipolar (III) Inmate

From: Southern Alabama, USA
Insane since: Sep 2000

posted posted 06-13-2002 20:51

In my color randomizer that I mentioned in another thread (http://www.webwhirlers.com/color/spinwheel.asp), I use ASP to randomize colors.
In the code I use a database to do the conversion from Dec to Hex.

I now wanted to make the page faster, and do the randomizing and conversion in the same page. However, I discover that the RND is not very random at all.

<%
Function R(max)
Randomize
R = Int(Rnd * max)
End Function %>

<%
A1 = R(255)
B1 = R(255)
C1 = R(255)
%>

<% = A1 %><br>
<% = B1 %><br>
<% = C1 %>

In the previous code, the A1 seems to be more or less random, but the relations between the different values is almost always the same - B1 is about 21 less than A1 and C1 is 56 less than B1.
How do I do to get each number random, and not dependent on each other?

My guess is that it worked better before when I had the database connection because that causes some delays, and the random number is based on the computer clock?

Any ideas?

Thanks



Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-13-2002 22:18

Perhaps if you only said "Randomize" once instead of each time? That might reset it or something.

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 06-14-2002 08:10

you're quite right - the call for randomize is

code:
randomize [number]


if you leave out the number, the the system timer is used as the seed value for the rnd function
you might get better results by randomizing with the system time coupled with a further seed value either randomly generated or of your own choosing for each colour

hth
I:.

ZOX
Bipolar (III) Inmate

From: Southern Alabama, USA
Insane since: Sep 2000

posted posted 06-14-2002 15:39

Thank you Slime!
Moving the "randomize" out of the function and to the beginning of the file did seem to do the trick. I guess it is still not completely random, but it seems to be random enough for what I am looking for.

Someoneinverse - that's what I thought. I am not sure I fully understand how to do what you suggest though. You think this would make it better, and more truly random?

Thanks

fizgig
Nervous Wreck (II) Inmate

From: West Bloomfield MI
Insane since: Aug 2001

posted posted 06-14-2002 16:46

You could try making the number in there somewhat random

like taking the IP and doing some funky things

myNumArray = split(Request.ServerVariables("REMOTE_ADDR"), ".")

num = 1
for x = 1 to ubound(myNumArray)
num = num * myNumArray(x)
next

randomize(num)




Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-14-2002 22:16

I believe every time you get a random number, it uses that random number as the seed for the next one. So calling Randomize more than once probably doesn't do you any good.

I'm not certain though.

« BackwardsOnwards »

Show Forum Drop Down Menu