473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Oder by Rnd() isn't random

I'm trying to order a recordset randomly. I've tried the following

ORDER BY Rnd(ProdID) - ProdID is my primary key

I've read that this will be random but will always return the same random
order. I've also read that using the following should resolve this

ORDER BY Rnd(Timer()) - this still gives me the same problem

I've only got 16 recors in the DB at the moment if this is relevant.

Can anyone help me return my recordset in a new random order every time
EVERY time

Thanks in advance
Jul 19 '05 #1
6 7263
Rnd() is only random based on the seed. ProdID is going to be a constant
seed, and I don't think timer() is going to vary enough between refreshes to
see a difference.

Why don't you store the result in getrows, and then iterate through the
array in using a random order?

A

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:C8*********************@news-text.cableinet.net...
I'm trying to order a recordset randomly. I've tried the following

ORDER BY Rnd(ProdID) - ProdID is my primary key

I've read that this will be random but will always return the same random
order. I've also read that using the following should resolve this

ORDER BY Rnd(Timer()) - this still gives me the same problem

I've only got 16 recors in the DB at the moment if this is relevant.

Can anyone help me return my recordset in a new random order every time
EVERY time

Thanks in advance

Jul 19 '05 #2

Would help better if you say what DB your using...
if your using SQL Server try

ORDER BY NEWID()

HTH
Al
On Fri, 14 Nov 2003 17:19:30 GMT, "Andrew Banks"
<ba****@nojunkblueyonder.co.uk> wrote:
I'm trying to order a recordset randomly. I've tried the following

ORDER BY Rnd(ProdID) - ProdID is my primary key

I've read that this will be random but will always return the same random
order. I've also read that using the following should resolve this

ORDER BY Rnd(Timer()) - this still gives me the same problem

I've only got 16 recors in the DB at the moment if this is relevant.

Can anyone help me return my recordset in a new random order every time
EVERY time

Thanks in advance


Jul 19 '05 #3
Very good point!

I'm using and Access DB and I'm afraid I have no option to change to SQL
Server
"Harag" <ha***@REMOVETHESECAPITALSsofthome.net> wrote in message
news:kg********************************@4ax.com...

Would help better if you say what DB your using...
if your using SQL Server try

ORDER BY NEWID()

HTH
Al
On Fri, 14 Nov 2003 17:19:30 GMT, "Andrew Banks"
<ba****@nojunkblueyonder.co.uk> wrote:
I'm trying to order a recordset randomly. I've tried the following

ORDER BY Rnd(ProdID) - ProdID is my primary key

I've read that this will be random but will always return the same random
order. I've also read that using the following should resolve this

ORDER BY Rnd(Timer()) - this still gives me the same problem

I've only got 16 recors in the DB at the moment if this is relevant.

Can anyone help me return my recordset in a new random order every time
EVERY time

Thanks in advance

Jul 19 '05 #4
What if you declare a function like this:

Public Function GetRandom(ByVal dummy As Long) As Double
Static blnRandomized As Boolean
If blnRandomized <> True Then
blnRandomized = True
Randomize
End If
GetRandom = Rnd()
End Function

Then add a column to your query, eg GetRandom([ProdID]) AS SortOrder
and ORDER BY SortOrder

The dummy arg is there because I have found that if Access sees a function
with no args it assumes that it always returns the same result and so it
just evaluates it once and uses that result for every row it returns.

HTH
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:Df*******************@news-text.cableinet.net...
Very good point!

I'm using and Access DB and I'm afraid I have no option to change to SQL
Server
"Harag" <ha***@REMOVETHESECAPITALSsofthome.net> wrote in message
news:kg********************************@4ax.com...

Would help better if you say what DB your using...
if your using SQL Server try

ORDER BY NEWID()

HTH
Al
On Fri, 14 Nov 2003 17:19:30 GMT, "Andrew Banks"
<ba****@nojunkblueyonder.co.uk> wrote:
I'm trying to order a recordset randomly. I've tried the following

ORDER BY Rnd(ProdID) - ProdID is my primary key

I've read that this will be random but will always return the same randomorder. I've also read that using the following should resolve this

ORDER BY Rnd(Timer()) - this still gives me the same problem

I've only got 16 recors in the DB at the moment if this is relevant.

Can anyone help me return my recordset in a new random order every time
EVERY time

Thanks in advance


Jul 19 '05 #5
Its a little messy but you could do the following:

1) Create an access module
2) Paste the following:

Public Function NewRnd(ProdID As Integer) As Integer
Dim intRnd As Integer
intRnd = Rnd * 1000
NewRnd = intRnd
End Function

3) Using the following in your Order by clause:
ORDER BY NewRnd([prodID])
"Carl Johansen" <ca**********@btinternet.com> wrote in message news:<bp**********@titan.btinternet.com>...
What if you declare a function like this:

Public Function GetRandom(ByVal dummy As Long) As Double
Static blnRandomized As Boolean
If blnRandomized <> True Then
blnRandomized = True
Randomize
End If
GetRandom = Rnd()
End Function

Then add a column to your query, eg GetRandom([ProdID]) AS SortOrder
and ORDER BY SortOrder

The dummy arg is there because I have found that if Access sees a function
with no args it assumes that it always returns the same result and so it
just evaluates it once and uses that result for every row it returns.

HTH
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:Df*******************@news-text.cableinet.net...
Very good point!

I'm using and Access DB and I'm afraid I have no option to change to SQL
Server
"Harag" <ha***@REMOVETHESECAPITALSsofthome.net> wrote in message
news:kg********************************@4ax.com...

Would help better if you say what DB your using...
if your using SQL Server try

ORDER BY NEWID()

HTH
Al
On Fri, 14 Nov 2003 17:19:30 GMT, "Andrew Banks"
<ba****@nojunkblueyonder.co.uk> wrote:

>I'm trying to order a recordset randomly. I've tried the following
>
>ORDER BY Rnd(ProdID) - ProdID is my primary key
>
>I've read that this will be random but will always return the same random >order. I've also read that using the following should resolve this
>
>ORDER BY Rnd(Timer()) - this still gives me the same problem
>
>I've only got 16 recors in the DB at the moment if this is relevant.
>
>Can anyone help me return my recordset in a new random order every time
>EVERY time
>
>Thanks in advance
>


Jul 19 '05 #6
Indigo Montoya wrote:
Its a little messy but you could do the following:

1) Create an access module
2) Paste the following:

Public Function NewRnd(ProdID As Integer) As Integer
Dim intRnd As Integer
intRnd = Rnd * 1000
NewRnd = intRnd
End Function

3) Using the following in your Order by clause:
ORDER BY NewRnd([prodID])

That will not work in queries executed from non-Access applications. Custom
functions in Access modules are not accessible to the Jet engine when Access
is not involved in the process.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leslie | last post by:
I need to get 20 random records from a table based on a condition. The condition isn't a problem. I have tried select top 20 *, rnd(field) from table, but that gets me the top 20 records. I need...
0
by: Howard Kaikow | last post by:
I can seed Randomize to assure that I get the same sequence, using Rnd each time. I can seed Random to assure that I get the same sequence, using Next, each time. Is there any way to seed...
5
by: V Power | last post by:
Hi, I have just been putting together a random number generator to practice with VB .NET. The Rnd command on its own works fine, however as soon as I add = 10 to the string I get a return value...
11
by: bogusexception | last post by:
(or.. "I'm getting too much Tails and not enough Heads") I'm running into a very strange problem with random numbers and long numbers. To demonstrate the problem, I've created a simple test....
4
BSOB
by: BSOB | last post by:
ok, we've all used random, and if we've used it enough we've figured out that it is infact a predictable function. and honestly, i was ok with that. until i realized that the rnd function's...
1
by: Radu | last post by:
As simple-to-remember-but-unique confirmation numbers, I need to generate six random characters (ASCII 65 to 90, inclusive): Randomize() objStringBuilder.Append(Chr(CInt(Int((25 * Rnd()) +...
2
by: McKirahan | last post by:
Can someone show me the JavaScript equivalent to the following VBScript? Thanks in advance. Randomize For i = 0 to 15 intRnd = Int((16 * Rnd) + 1) Next Perhaps the follwoing is a start?
13
by: Nick | last post by:
Hi there, I'm trying to create a random number via a seed in VB.NET and C++, 2 different applications. I want to be able to use the same seed and get the same random number but unfortunately...
1
by: vineet1987 | last post by:
i want to generate a series of random numbers like 00101 01011 01111 01010 11101 it is a 5*5 matrix and is random every time upon execution my code is:-
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.