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 RepliesI 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 RepliesI 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?
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:
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!
I am trying to generate a random number between 1 and 100 into a label, using c#....
View Replies View RelatedI am developing a online test application(multiple choice ques) So for that i need to shuffel the questions randomly. eg there will be 60 Questions in total. If say 50 users are connected to it, all will be having same 60 questions but its order should be different.
i am using below code to randomly generate questions numbers but the problem with this code is it is repeating the number.I want to generate non repeatable numbers. Can anyone help me out to do it.
Dim my_num,max,min
Dim i
i = 0
max=60
min=1
For i = 1 to 60
Randomize
my_num=int((max-min+1)*rnd+min)
Response.Write my_num & "<br>"
Next
I know thats theres already a few posts about this subject but I need to create 3 random numbers of any size, I've used the following code -:
randomnumber1 = int(rnd*9)+1
randomnumber2 = int(rnd*9)+1
randomnumber3 = int(rnd*9)+1
but it always returns, 7,5 and 6..
Not very random as you can see
I have a code to create a random string of letters. The number of them can be whatever I desire.
what i would like to do, is have it both letters and integers. how would inmodify this code to allow that ....
I am trying to create a random value between 10 and 1,000,000. I am using the following code but it is creating numbers between 10,000 and 999,999. How can I fix it.
<%
Highest=1000000
Lowest=10
Randomize
Val_Rand=CStr(CLng((Highest-Lowest+1)*Rnd+Lowest))
response.write(val_rand)
%>
The code never gives small numbers like 10, 15 500, 250, 257 etc.
I am using DreamweaverMx to create a football website that stores players to a databse and when they join a game there is a function to randomize a number for each player and store it on a second databse and from the database using sql to link my databases together so that a players details are posted on a page of my website.
View Replies View RelatedI have this situation:
each user has some amount of points, for example:
table:users
user_id --- user_name --- points
1 --- user1 --- 100
2 --- user2 --- 100
3 --- user3 --- 100
4 --- user4 --- 200
5 --- user5 --- 500
-------------------
total points: 1000
I want to generate random selection of user, according to their points respectively, so the more points he has, the more likely he will be selected:
user1 in 10% cases
user2 in 10% cases
user3 in 10% cases
user4 in 20% cases
user5 in 50% cases
this percentage is respective to their points; I put some rounded numbers in the example - so total points of 1000 equals 100% - but they can have any amount of points: 1, 200, 3672 etc.
I’m having problems on how to randomiz numbers and delete the ones that have been displayed.
My first step is to take some numbers:
21, 32, 35, 4, 15 and randomize theese so the ouput may look something like this:
35, 21, 15, 32, 4
My second step is to display the first number (35), then when a user clicks on a link I want the second of my random number (21) to be displayed and I also want to delete the first number (35) that has been displayed. And this routine (display number, delete previous number) should continoue untill there is no more numbers. So again, I wnat to step through all my random numbers and delete the ones I have displayed.
Example: ....
not after code, just thoughts, suppose i'm generating a random 8-digit pin number for our clients, first i'll be checking against the db to see if it already exists before assigning it. what i might do for that is getstring all of the exsiting pins at the top of the script and just keep performing an instr until i get a 0. (i dont expect to ever go above a thousand clients for this system and hopefully my initial number will be random enough that these checks are for backup/redundancy assertion anyway)
but anyway, the main problem is: i dont want to generate a random pin that is one (or maybe two) digit(s) different from another,. i.e.
11111111 is too close to 14115111 and much too close to 11111811. 11121111 is right out of the question as it can be entered as a typo, as is 11111411 because of the numpad
so i'm after thoughts on how to perform that check, i suppose if i went with the "big string of all pins that went before" check i could perform a number of regex searches on the string. i.e.
my pin is 12345678 and i dont want ony to be one digit different so i'd check the string against .2345678 1.345678 12.45678 and so on. think i just answered my own question, anyone else got any ideas? especially for the two digit case (dont want to be performing 36 regex checks do i!)
I am trying to write an array of random numbers to a database. The array part is working fine, but when I go to update the dataabse, it inserts the last value of the array into all the fields in the database .....
Dim MyValue,sqlRandom
Dim arrayRandom(8)
for i = 1 to 8
Randomize
MyValue = Int((100 * Rnd) + 1)
arrayRandom(i) = MyValue
response.write "<p> Array Value:" & arrayRandom(i)
sqlRandom = "UPDATE CarParkDetails SET FreeSpaces = '" & arrayRandom(i) & "'"
Conn.execute(sqlRandom)
next
I can't see whats wrong!
i have two numbers that i need to combine and then depending on the result i need to write different instructions to the browser. Code:
View Replies View RelatedI 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 View Relateddoes exist any command to get random row from target table in target database and then use this row ?
View Replies View RelatedOk 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.
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?
<%
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?
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.
I'm working on asp project, access 2000 at backend.I can write arabic text and arabic
numbers in textbox and save them in database.but if i see these records, arabic text and arabic numbers,it is ok,if my computer is arabicenable.
If my computer is not arabic enable then it show arabic number into english numbers.
how can i show arabic numbers instead of english numbers if my computer is not arabic
enable.i'm working on a project i have to complete it.How can i convert english numbers that are coming from database and convert that numbers in arabic for show.
I have use
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
I shall be very thankful to you for this purpose.
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>
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:
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?
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:
Just started learning ASP about ten minutes ago.
Currently experimenting with forms.
could someone please tell me what is wrong with this code:Code:
<%
Resonse.Write Request.Form("myform") + Request.Form("myform2") & "<br />"
%>
Im trying to get two numbers to add together from a form.
I get this error when i use that code:
Quote: Microsoft VBScript runtime error '800a01a8'
Object required: ''
/Jaynesh/asptest.asp, line 14
how can i check if a variable is an even number
View Replies View Relatedi want to add two numbers in server script with VB script. how to do it.
View Replies View RelatedI Have this form in page1:
<form method="post" action="page2.asp">
<input type="checkbox" name="numb" value="10">
<input type="checkbox" name="numb" value="20">
<input type="checkbox" name="numb" value="30">
<input type="checkbox" name="numb" value="40">
</form>
Now what I want is to add the checked values in page2.
For example :
if checkbox1 and checkbox3 gets checked I want to add the values in the
checkboxes which in this case is 10 + 30 and get the total sum (40).
Hope this makes sense?
So how do I retrive the checked values and then add the checked values
with eachother to get the total?
i need to oredr a set of numbers. the numbers are "06/9","95/1","95/6","06/3" and so on. the thing is that these need to be ordered form the second number, so it shoudl be ordered thus: "95/1","06/3","95/6","06/9". how can i do this? at the moment just as an attempt im splitting the number either side of the "/" like this:
var regNo = "12/09"
var yearStart = 0
var yearEnd = regNo.indexOf("/")
var year = regNo.substring(yearStart, yearEnd)
var itemStart = regNo.indexOf("/") + 1
var itemEnd = regNo.length
var itemNo = regNo.substring(itemStart, itemEnd)
but where do i go form here?
I am converting bites to Megabytes in an operation. How would I trim the result to only go to 2 decimal places?ex:
Response.Write(file.FileName & " (" & (file.Size/1048576) & "Mb)<BR>")
i know how to code it in javascript but failed to do it in asp. there are 12 digits of number. exmple like this 871205106599. i want to check every single digit when user clicks Submit button.
View Replies View Related