| Author |
Topic Search Topic Options
|
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 11:43am |
|
When giving the Random function a seed it will also produce the same number and thus if your random seed is constant (in this case the ID of a record), it will always be sorted the same way. This may be different from the default sort, but the rows will always be in the same order sorted by Rnd(id). Remove the seed and sort by Rnd() and you should get random sorting. I don't use Access so I can't tell you explicitly that it will work.
An alternative would be to count the number of records in the database and use VBScript's Rnd() function to select the random record and then query for the that particular record. This is the method that most Ad program use.
NewID() only works with SQL Server so that would not help you with an Access database.
|
|
|
 |
cosmic cat
Groupie
Joined: 14 May 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 12:27pm |
I've not tested the Access one either, sorry should have made that clear; it's just a snippet I picked up which looked like it should work. The SQL one works though, I use it a lot for randomly picking out records..
I'm taking a look in Access (2000) now to see what it does. Hmm, seems to always reverse the order of the records, so the top one would always be the last record.
I'll have a play later see if I can make it work!
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 12:44pm |
it worked, thanks to MorningZ post.
<% Dim Rand, RandS, RandHere Rand = "SELECT id, Make, Model, Image FROM eCatalog " set RandS = server.createobject("adodb.recordset") RandS.open Rand, Conn, 3, 1
Dim rndMax rndMax = CInt(RandS.RecordCount) RandS.MoveFirst Randomize Timer Dim rndNumber rndNumber = Int(RND * rndMax) RandS.Move rndNumber
RandHere = RandHere & "<img border=""0"" onError=""src='GfX/clear.gif'"" src=""eShop/" & RandS(1) & ".gif""><BR>" RandHere = RandHere & "<img border=""0"" src=""eShop/" & RandS(3) & """>" response.write RandHere %>

Edited by zMaestro
|
 |
zMaestro
Senior Member
Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 12:53pm |
cosmic cat wrote:
I've not tested the Access one either, sorry should have made that clear; it's just a snippet I picked up which looked like it should work. The SQL one works though, I use it a lot for randomly picking out records..
I'm taking a look in Access (2000) now to see what it does. Hmm, seems to always reverse the order of the records, so the top one would always be the last record.
I'll have a play later see if I can make it work!
|
thanks a lot.. it is working fine with the code i posted. 
|
 |
cosmic cat
Groupie
Joined: 14 May 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 6:04pm |
Cool 
Shame there's not a simpler way in Access like SQL Server though, and when I was digging around in Access earlier, I remembered how much I've forgotten about Access (haven't used it for a couple of years now since we moved to MS SQL Server).
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 October 2003 at 9:44pm |
I remember testing this with Access a while back and we couldn't get it to reseed on the same connection, or was it a pool of connections.... There was some type of work around but I can't find where I saved it.
The SS one comes in quite handy though.
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
sam98
Newbie
Joined: 23 October 2003
Location: United Kingdom
Status: Offline
Points: 2
|
Post Options
Thanks(0)
Quote Reply
Posted: 23 October 2003 at 8:50am |
|
how can we distribute rows in a database
|
 |
sam98
Newbie
Joined: 23 October 2003
Location: United Kingdom
Status: Offline
Points: 2
|
Post Options
Thanks(0)
Quote Reply
Posted: 23 October 2003 at 8:51am |
|
how can we distribute columns in a database
|
 |