|
Comments
|
Steve Culshaw on
11/23/2010
Good concise overview of RAND
|
|
|
very good tip
|
|
|
Thank you Andy.
|
|
|
simple and good..
|
|
Tahir A. Syed on
11/23/2010
Daily hints is a simple reminder & improve our knowledge, thanks...Tahir
|
|
|
Try rand(rand()). You'll see that it still acts as a seed and the result does not change even though you would expect the internal rand() to generate a new seed each time
|
|
Mike Jackson on
11/23/2010
Hey Andy,
One of the questions I get alot is, how to get a integer between an upper and lower range, like 1 and 1000. If you do
select rand()*1000
you will get something like 124.114808284108
so if you cast that as an integer you will get something like...
select cast(rand()*1000 as int)
124
Now you need to add 1 to it or you will possibly get a zero and never achive the upper limit.
select cast(rand()*1000 as int)+1
So if you need a 1000 random numbers just put that a loop and let it run.
|
|
|
Hi Andy,
I have a monthly job that makes use of the RAND function.
Our helpdesk does a monthly self-audit of 20 random network accounts.
To accomplish this I read the Active Directory accounts and place the
names in a table with an identity column that begins at one and increments
by one. Subsequently I use a 20 iteration WHILE loop and the RAND function
to randomly read 20 employees from that table. Works very well.
Thanks for all the great videos.
df
|
|
|
Interesting comment above by C Boos on RAND(RAND()). Anyone know why that is?
|
|
|
GOOD didnt know tht sql could do tht !!!
|
|
Jack Hellmuth on
11/23/2010
Is the rand funtion without a seed actually implemented with a system seed?
|
|
|
decent, would have like to see you put in example of how to get larger random numbers between a scale.
|
|
Dennis Allen on
11/23/2010
How about a key exchange for one time pad generation. You could generate and share some random seed
DECLARE @secret int;
SET @secret = cast(cast(newid() AS varbinary(4)) AS int);
And then use the RAND() function to generate key sets, perhaps building key tables in 8 byte blocks
cast( rand()*9223372036854775807-9223372036854775808 AS bigint )
and then assembling those into 512 byte keys or what not. There are better ways... but you could do that.
|
|
|
I did not know this.
|
|
|
Very cool
|
|
Syed Arshad on
11/23/2010
Could not catch the catch
|
|
|
Might have been good to describe the purpose of the seed value (to generate a repeatable sequence of random numbers). Also, it might be good to discuss good expressions for the seed to generate unpredictable random sequences.
|
|
SCOTT SNYDER on
11/23/2010
The video got me started and thinking about how to use the function. I did some playing with it and research to come up with a way to autopopulate test data. By putting in the test data I was able to have groups test their business calucations and queries until I was ready to go with the actual data.
|
|
|
Excellent tips
|
|
Faisal Lodhi on
11/23/2010
Thanks you
|
|
|
Nice concept for random number
|
|
Rajiv Gupta on
11/24/2010
Very good!!!
|
|
|
That's a great video, like the Go 10 trick, but what you do with Rand()?
|
|
|
I've use RAND to generate random numeric data (along with some additional arithmetic functionality to define a range of numeric data).
|
|
|
So could you use this as a random generator for a quarterly review?
|
|
|
good examples of rand
|
|
|
should point out that select *,rand() from any_table
will return same random number with each row. This prevents using it to select random records
|
|
|
nice
|
|
|
Can you show an example of how to get a different output every time (truely random)?
|