473,608 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
+ 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 7279
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****@nojunkb lueyonder.co.uk > wrote in message
news:C8******** *************@n ews-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****@nojunkb lueyonder.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***@REMOVETH ESECAPITALSsoft home.net> wrote in message
news:kg******** *************** *********@4ax.c om...

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****@nojunkb lueyonder.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****@nojunkb lueyonder.co.uk > wrote in message
news:Df******** ***********@new s-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***@REMOVETH ESECAPITALSsoft home.net> wrote in message
news:kg******** *************** *********@4ax.c om...

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****@nojunkb lueyonder.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**********@b tinternet.com> wrote in message news:<bp******* ***@titan.btint ernet.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****@nojunkb lueyonder.co.uk > wrote in message
news:Df******** ***********@new s-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***@REMOVETH ESECAPITALSsoft home.net> wrote in message
news:kg******** *************** *********@4ax.c om...

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****@nojunkb lueyonder.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
1430
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 20 random records. I would prefer to use SQL only for this if it is possible. Thanks in advance.
0
813
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 Randomize so that Rnd starts with same value as Next? As a test, I used 9660 as the seed to both.
5
2530
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 of false. If i use the string CStr(Int(Rnd() = 10)) I get a return value of 0. What am I doing wrong - because the debugger seems to think everything is fine.
11
1696
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. Consider that a series of coins are to be "flipped" all at once. The result of the combined flip are a series of bits (0 = tails or 1=heads). These bits form a number, and that number can be represented by a type long. OK. Not so bad so far. To...
4
3195
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 quazi-frequency happens to be the width of my screen. which happens to be an issue. 1) does anyone know what im talking about? 2) does anyone know of a good way to make a random number that doesnt have a steady frequency? if people dont know what im...
1
1788
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()) + 65)))) Randomize() objStringBuilder.Append(Chr(CInt(Int((25 * Rnd()) + 65)))) Randomize() objStringBuilder.Append(Chr(CInt(Int((25 * Rnd()) + 65)))) Randomize()
2
3498
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
3662
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 VB.NET's Random class produces a different set of results than the C++ rnd function. I can't see any reference of rnd being used via API declarations and am just trying to find a way of generating a random number via seed that is identical in...
1
2027
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
8013
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8503
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8488
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3977
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2482
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 we have to send another system
1
1613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1345
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.