How to Seed Rand( ) With A Timestamp

I run a traffic exchange script on an SQL server.  I have noticed that it does not randomize the sites very well and I heard that i can fix this by "seeding rand with a timestamp."  I don't know much about sql so I dont know what that means.  I can administer it with PHPmyAdmin.  If anyone can help me out with this, I would be very grateful.  
smileinjectionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PanimuCommented:
Rand takes a value between 0 and 1 for a seed. If you don't give it one it has some of its own. If you use the same seed it can end up giving the same values.

So by using the time as a seed you can come close to guaranteeing your code provides a new seed each time. So use GETDATE to pull out sections of the current time and feed it to Rand

SELECT RAND((DATEPART(ss, GETDATE()) * 1000)
+ DATEPART(ms, GETDATE()))

So this example uses the current seconds and milliseconds to generate a rand.
0
smileinjectionAuthor Commented:
Ok, looks good.. but how do I get to where I can edit that function using PHPMyAdmin?  Or.. is it in a text file that i could get via ftp?  I don't want to mess this up because I have many people using my script and I don't want any downtime.  Thanks
0
Anthony PerkinsCommented:
A word of caution from BOL when using Rand in a Select:

<quote>
When you use an algorithm based on GETDATE to generate seed values, RAND can still generate duplicate values if the calls to RAND are made within the interval of the smallest datepart used in the algorithm. This is especially likely if the calls to RAND are included in a single batch. Multiple calls to RAND in a single batch can be executed within the same millisecond, which is the smallest increment of DATEPART. In this case, incorporate a value based on something other than time to generate the seed values.
</quote>

Also, don't forget this question:
Scanning through ip ranges in Visual Basic.  Net Send
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20495079.html

Anthony
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

smileinjectionAuthor Commented:
Well, you can check out my script at smileinjection.com/exchange.  It wont matter if it generates duplicates.. I just want it to be more randomized than it is now... I jsut dont know how to do it using shared hosting and phpmyadmin.
0
smileinjectionAuthor Commented:
Well, you can check out my script at smileinjection.com/exchange.  It wont matter if it generates duplicates.. I just want it to be more randomized than it is now... I jsut dont know how to do it using shared hosting and phpmyadmin.
0
PanimuCommented:
I'd have to see the actual script source (which may not be wise to release, depends how much you care about it). Can't judge much from seeing the HTML output only.
0
smileinjectionAuthor Commented:
Well, can you just tell me how to put that code in my Rand() function?  I have access too phpMyAdmin, ssh, and ftp.  Thanks.
0
PanimuCommented:
Replace Rand() with

RAND((DATEPART(ss, GETDATE()) * 1000) + DATEPART(ms, GETDATE()))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smileinjectionAuthor Commented:
oh!  hehe.. see, I dont know much. :)  THanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.