Seemingly... I haven’t sat and tested just how 'random' it actually is but
it seems to always be random enough for my purposes. 

The only 'gotcha' I can think of when selecting more than 1 record at a time
with it... is that they may always be 3 sequential records in the
database... but if you ran 3 separate queries...or ordered them with random
columns and directions like I posted before... problem solved

It generates unique ids for the records and orders by that... you'd have to
get a better explanation of what it's actually doing from someone else
though :)

But try a test... just select something and order your query by newid()

Refresh it a few times... you might be surprised :)

..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
 
 

-----Original Message-----
From: Stuart Kidd [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 19, 2005 12:43 PM
To: CF-Talk
Subject: RE: Random Numbers

Yes, it's MS-SQL.  I can sort them but sometimes there may be 100 entries
and i'd like to pick random numbers not just the top 3.

When you mean newid - does that do a random pick?

Thanks,

Saturday

----------------------------------------
From: "Bobby Hartsfield" <[EMAIL PROTECTED]>
Sent: Monday, December 19, 2005 12:39 PM
To: CF-Talk <[email protected]>
Subject: RE: Random Numbers 

What database are you using?

In SQL server you can select the top 3 and order by newid()

I'm pretty sure you can do that in MySQL too... I'm just not sure if it's
actually 'newid()' in MySQL

-----

Else, I can think of a couple different ways to do it....

The simplest way I can think of...

Get a list of all the IDS from the table

So you'd have a list of IDS like "1,2,3,4,5,6,7,8,9"

Then loop from 1 to however many records you want while grabbing a random ID
from the list each time and removing it from the list to ensure it doesn't
get selected again...

thisposition))>

When its done, #randomids# will hold 3 random ids then you just 
select * from table where id in (listofids)

That's all untested of course and knowing me... there's a typo somwhere...

If there are a ton of records and you don't want to grab all the ids
everytime... just grab half or something and randomly order them by
different columns and/or asc/desc

Eg...

Select ID from table
Orderby #orderby# #orderdirection#

....:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com

-----Original Message-----
From: Stuart Kidd [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 19, 2005 11:32 AM
To: CF-Talk
Subject: Random Numbers

Hi guys,

I'm trying to write an app which will choose three random numbers for a
competition based on how many etnries there are.  I'm having problems trying
to work out a way not to choose the same number twice, is there a way to do
that which will fit into my CFLOOP structure?  Or is there a better way to
do it?





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227281
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to