473,484 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 7267
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
1415
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
801
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
2517
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
1677
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
3189
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
1777
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
3487
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
3642
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
2021
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
7082
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7144
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6813
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4529
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1359
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.