Random Select

I have the following select statement, but need to randomise the results to draw just 1 record at a time for banner displaying. How can I do it? ....

View Replies


ADVERTISEMENT

Select Random Row In Database

does exist any command to get random row from target table in target database and then use this row ?

View Replies View Related

Random Numbers Select

I have 30 numbers. I need to select randomly 10 out of the given 30. A number must not repeat ( eg. i can't have number 10 twice ). How can i do this??

View Replies View Related

Select RANDOM Record

Ok here is what I'm trying to do. I want to grab a random record from a specific table. This is how I am doing it now:

x = 0
Set rs = Conn.Execute("SELECT Count(*) as total FROM [user] WHERE active = '1'")
If rs.EOF <> True then
total = rs("total")
End if
Randomize timer
randnum1 = int(rnd * total)
If randnum1 = 0 then
randnum1 = 1
End if
rs.close
set rs = nothing

Set rs = Conn.Execute("SELECT * FROM [user] WHERE id = '" & randnum1 & "' ")
Now that would work fine, BUT the id is a autonumber int of 1.

Now look at this example. Let's say I have 50 records, so I have the ID values of 1 through 50. Now I delete record number 46. So now my count goes up to 49. So the random number will pull up ANY number between 1 and 49, so if it pulls up 46 then BAAAM record can not be found.

There has to be an easier/more efficient way of getting a random record. I don't plan on deleting any records, but I just don't feel this is the best way of doing this.

View Replies View Related

Select 5 Random Records

I want to select 5 random records from my database..I tried to suft the net and foundout this sql

SELECT TOP (3) Question, Choice1, Choice2, Choice3, Choice4
FROM Question

But when i tried to execute,i t always gave me the most top 2 records. why?Is this sql statement woring?How can i select 5 random records from the database?

View Replies View Related

Random Record With SELECT TOP Does NOT Work

<%
Dim oConn, oRS, randNum
Randomize()
randNum = (CInt(1000 * Rnd) + 1) * -1
Set oConn=Server.CreateObject("ADODB.Connection")
Set oRS=Server.CreateObject("ADODB.recordset")
oConn.Provider="Microsoft.Jet.OLEDB.4.0"
oConn.Open Server.MapPath("temp.mdb")

oRS.Open "SELECT TOP 1 EMAIL_ADDRESS, r = Rnd(" & randNum & ") FROM TABLE1 ORDER BY r", oConn, adOpenStatic, adLockReadOnly

Response.Write oRS("EMAIL_ADDRESS")

oRS.close
oConn.close
Set oConn = nothing
Set oRS = nothing
%>

this gives the error: "No value given for one or more required parameters".

what i would really LOVE is for someone to fill in whatever required parameter im missing, but more important i would like to understand whats going on. there are people who go through life dumb and happy once something "works", but i need to understand how and why its working. even if this code did work, im confused with the SELECT statement (no, i dont have much SQL experience aside from basic queries). what is the "r = Rnd" line doing in the middle of the querie? how am i ordering by r?? also, i dont have an indexed, primary "ID" field in this databae. is that ok for this code to work?

View Replies View Related

Select Random Word From File

While i'm here, do you know how to select a random word from a text file?

Txt file is like this:

word 1
word 2

etc.

View Replies View Related

Function To Select 3 Random Numbers Which Are Distinct

I need to generate three random numbers between 1 and 100, but they need to be different.

e.g. 3,43,88 would be fine but 5,76,76 would not.

The function I have to generate a single random number is:

function funRandomNumber(intHighestNumber)
randomize
funRandomNumber = int(rnd * intHighestNumber) + 1
end function

called by: funRandomNumber(100)
Can anyone see how this can be modified to do what I need?

View Replies View Related

How Do I Make Random Images Not Random?

However, what I want to do is include a request.querystring("ID"), so that IF an ID is defined, eg ID=3, , it will display the relevant (not random) information. I've tried this every way I can think and get type mismatches, etc etc. It's probably really simple but I can't see it.

<%
limit=3
redim link(limit)
redim image (limit)

link(1)="xxx"
image(1)="image1.jpg"

link(2)="xxx"
image(2)="image2.jpg"

link(3)="xxx"
image(3)="image3.jpg"

randomize
random=int(rnd*limit)+1

%>
<center>
<a href="<%= link(random) %>">
<img src="<%= image(random) %>" border="0"></a>

View Replies View Related

Making It Random (getting Random Numbers)

I just wanted to know whats the best way to generate 50 or say X amount of number at random without having to repeat any of the previous number...

so far I've the following:

[VBS]<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
function RandomNumber()
dim theRandom

Randomize
'RandomNumber = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

theRandom= Int((99 - (0) + 1) * Rnd + (0))

if (theRandom<10) then theRandom = "0" & theRandom

RandomNumber = theRandom
end function
%>[/VBS]

and then I've this in the body of HTML doc: Code:

View Replies View Related

Random Token Generator - Not Really Random

We have the need to have a random token (a 16 char alphanumeric field) to be used as the key for one of our SQL tables. I have created a random token generator, however after only 3 months in production, it appears that we had an instance where a token that already existed in the tables was created. There are 3810 records currently in the database so it isn't like there are billions of records there.

I contacted an old college buddy of mine who is a mathematician, and he claims, assuming that random really does mean random, that the chances of getting a duplicate token are 1 in 79.5 septillion (79,500,000,000,000,000,000,000,000).

So my conclusion is that this was either a complete freak of nature occurance, or my random generator isn't really all that random. Here is the code behind how I am generating this: Code:

View Replies View Related

Random Number Not Random

I am trying to generate a random number. I am using randomize and then rnd to return a decimal number between 100 and 120. This will give me a longitude. I am doing something similar to generate a latitude.

I created this on a page which refreshs every minute. I put these points into a map and they are showing up in groups of straight lines. Since rnd is time based will refreshing every 60 seconds return similar numbers?

View Replies View Related

Error Using <select></select>

I have written some code which should dynamically build a table which is then populated with questionas and possible answers. The format of the answers will vary ie they may be in the form of a radio button which will be rated from 1-5, checkbox or a selectbox.

The first problem I have is if I do not comment out <select></select> I get an error message saying the page can not be found. when I do take it out I get asp timeout. Code:

View Replies View Related

Random Row

I want to display data of a Random Member on my page.. and I did a search in these forums and I tried to do this:

[CODE] SELECT tblMiembros.*, tblDatosPersonales.*
FROM tblMiembros, tblDatosPersonales
ORDER BY rnd(isnull(tblMiembros.ID_APLICANTE) * 0 + 1)"[/CODE]

This doesnt throw any errors. but it always displays the same row... (first in database)

am I doing something wrong? am I missing something?

View Replies View Related

Regarding Random

I have a client asking me about random images on his site, basically I am using the following code:-

<%
 RANDOMIZE
 Response.write("<IMG SRC='../gfx/bg-img0" & INT((3)*RND()) & ".jpg'>")
 %> 

Agreed its not the best code, but he is finding that the same image could be repeated like three times in a run.

I have an include file which displays the image, and the random script is placed inside that include. So when he is going from page to page this is where the issue lies.

Can anyone help me out here, is it even possible to have a different image load each time, and not have them repeating.

View Replies View Related

Random Value

I am using random number to be used as a unique identifir. Since random numbers are in decimals I am using going to convert it into an integer and since I need to append this Id into my URL, I am converting it into a string. SO my formula looks like this.

CStr(Int((Highest-Lowest+1)*Rnd+Lowest))

S0 now every time a new record is generated would this formula generate a unique number for unique identification in the table. I can't see how it can do it. Say A user is assigned a random number; then another user subscribes so how would the server determines that the random value assigned to next user is not already assigned to any other user.

In case if this can't work (a unique ID for every user) then I'll stick to this very same formula and after the random number is generated, I'll check this number with the table in the database and see whether it's been assigned already. If yes, I'll request another random value, if not then I'll go with it. Is this the right strategy?

View Replies View Related

Random Image

I have done random image display with the help suggestion from this discussion form. now I want to provide link on each image. i.e. all the images display randomly, should have different link. is it possible? if yes, how?

View Replies View Related

Random Images

is there sombody who can helpme witht he following, i am ''pretty new'' to
php and am looking for a script to show images randomly at a 10/ 15 seconds
interval. is there anybody who can help me with this or does know where to
find a good template script for this?

View Replies View Related

Random Image

example:

When u see some sites ,
the advetisement images are changing ,

when ever the browser is refreshed...

.....

like tha i want to do that.....

View Replies View Related

Random Image

I have the below ASP function to display a random image from a folder.

<%
Function RandomImage(strPath)
Randomize()

If Right(strPath, 1) <> Chr(47) Then strPath = strPath & Chr(47)
strPhysical = Server.MapPath(strPath)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:Inetpubwwwrootpag-siteimages
andoms")
Set objFiles = objFolder.Files

For Each objFile in objFiles
strFile = LCase(objFile.Name)
strFiles = strFiles & strFile & vbTab
Next

strImages = Split(strFiles, vbTab)
If UBound(strImages) > 1 Then
RandomImage = strPath & strImages(Int(Rnd(1)*UBound(strImages)))
End If
End Function
%>

and this places the image in the HTML

<img name="Intropic" src="<%=RandomImage("images/randoms/")%>" width="211" height="158" alt="" />

but sometimes the script places a ._ before the image file name in the outputted HTML?

View Replies View Related

Getting Random Errors

I'm afraid I have a technical problem here. Basically what happens is that I'm getting some random errors(like Type mismatch... etc) that shouldn't under normal circumstances occur. Then I connect to my server via remote desktop and Recycle the application pool on which my asp pages run. Errors then disappear

View Replies View Related

Random ASP File?

I have a file where i want to call a random asp file using the "include file" statement. I know it can be done with images, but can it be done with other asp files? and how?

View Replies View Related

3 Random Records From DB

I want to take 3 records from a database. The selection must first take any record marked as priority and then random records (so there could be 3 priority records and no more or 1 priority and 2 random etc)
My theory is to build a recordset filtered by records marked priority, and if there are less than 3, build a second recordset of all the other records.
Questions
1, how can I select random records form the second recordset, without selecting the same one twice?
2, OR, could I write a sql statement which would randomly select 3 records from my table
3, Or is they a way I could write a query (view) in Access which would do the whole lot for me (select the priority records and then random records up to 3)?

View Replies View Related

Random Code

I set up a random code for people registering with my site.....

letters="1234567890abcdefghijklmnopqrstuvwxyz"
for i=1 to 16
Randomize()
rNum=Int(Rnd()*36)+1
code=code&mid(letters,rNum,1)
next

but for some reason it sometimes saves code as an empty string. When I register a fake name, ie zzz, it seems to work fine, but for some of my members is saves as an empty string.

View Replies View Related

Random Number

trying to get a random number from 0000 to 9999, is there an easy way to do this? i'm using this for a unique filename and want it to be 4 digits from 0000 to 9999.

View Replies View Related

Random String

How do i produce a random string.anything from A-Z or a-z or 1-9 for the password.how do i do that

View Replies View Related

Shuffling / Random

i have a db where ± 15 users stores multiple second hand items with images. Now i wish to display on the openingpage a list of all users with 1 item + image. So far no problem.

But now i wish to change the order of the users every time the pages open.

How can i shuffle the recordset before i load the users in a array, or how
can i shuffle the array after populating with the users? Code:

View Replies View Related

Random # Generation

I'm trying to sort a list of 10 people into two groups--RANDOMLY. I've gotten as far as to generate a random number and assign a name to it. I just need to know how to generate 9 more numbers, making sure no numbers/names repeat. Code:

View Replies View Related

Random Record From DB

I have a DB with 10 items and an SQL statement:

"SELECT * FROM myTable WHERE Activate=true"

How do I make it so that every time the page refreshes it will display a random record?

View Replies View Related

Random Include

I'm trying to get one of 3 files randomly included in an ASP page.

The thing is, when the code is printed out, it becomes a comment and it doesn't .. "include" the page..

Btw: I'm a PHP novice, and have no experience with ASP. I just looked up a few randomization tutorials and tried to get this working.

View Replies View Related

Random Numbers

I have a problem creating random numbers. I basically have this

Randomize()
iRandom = Int(10 * Rnd + 1)

If I do not wait a few sec before hitting the page again it will create the same random number as generated a few seconds before.Any idea why it is like that? Another way to reprocess the "bug" is to just fit F5 few times in a row and you end up with the same number being generated. Its annoying and I need some help to "fix" it!

View Replies View Related

Random Text

I have a script which show quotes randomly, Here is the code::

Code:
<%
Dim quotes(3), iNumber, iRandom
'Dim an array of 3 variables
quotes(1) = "This is quote 1"
quotes(2) = "This is quote 2"
quotes(3) = "This is quote 3"
iRandom = ubound(quotes)
randomize 'call random function
iNumber = Int((iRandom)* Rnd) 'get random quote number
Response.Write(Quotes(iNumber)) 'write output to screen
%>

How can i do a thing like:: (for example)

Show the Quote(1) on 10th September 2004

Show the Quote(2) on 11th Sep 2004

Show the Quote(3) on 12th sep 2004

Is that possible?

View Replies View Related

Random Number

x = ROUND((0.9+1.005*RND()-0.4),1)
y = INT(y * x)

This is what I'm trying to acheive:
- "Y" has a preset value between 1-100
- "X" should be random between 0.8 and 1.2
- "X * Y" is the final value of "Y" as a whole number

What I'm struggling with is getting the value of X to be random between 0.8 and 1.2....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved