Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jsawyer
Starting Member
2 Posts |
Posted - 2010-05-16 : 04:27:23
|
| Hi, I'm fairly new to using SQL and have never really used it to its' full potential. My main question is, could SQL handle the task I'm wanting and if so, how?I'm wanting to generate a random set of co-ordanates (x, y) that are unique as sets and not individual numbers. If I could also make it so they are not COMPLETELY random, as in, the first one is around (0,0) meaning the next one will be close to that sort of position, say (2,3) instead of making (100,100).Any help is most appreciated, thanks in advance!-Joseph Sawyer |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-05-16 : 04:34:37
|
Yes. Use RAND() function with a proper seed. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
jsawyer
Starting Member
2 Posts |
Posted - 2010-05-16 : 05:57:29
|
| Thanks for your reply. How exactly would I go about doing that?-Joseph Sawyer |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-16 : 07:32:24
|
| seehttp://sqlblogcasts.com/blogs/madhivanan/archive/tags/random+numbers/default.aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-05-16 : 07:33:09
|
SELECT FLOOR(5 * RAND()) AS x,FLOOR(5 * RAND()) AS yFROM master..spt_valuesWHERE Type = 'P' AND Number BETWEEN 1 AND 6orSELECT TOP(10) x, yFROM ( SELECT DISTINCT CHECKSUM(NEWID()) % 10 AS x, CHECKSUM(NEWID()) % 10 AS y FROM master..spt_values ) AS d N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|
|