How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of
variables??? 6 1819
A2 wrote on 28 mei 2007 in comp.lang.javascript :
How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of
variables???
You would have to write it.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Evertjan. said the following on 5/28/2007 5:30 PM:
A2 wrote on 28 mei 2007 in comp.lang.javascript:
>How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of variables???
You would have to write it.
Just make sure you don't search the archives because you might find an
answer to this very question, about 40 times :-)
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Randy Webb wrote on 29 mei 2007 in comp.lang.javascript :
Evertjan. said the following on 5/28/2007 5:30 PM:
>A2 wrote on 28 mei 2007 in comp.lang.javascript:
>>How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of variables???
You would have to write it.
Just make sure you don't search the archives because you might find an
answer to this very question, about 40 times :-)
Even so if [s]he wants to make a script, [s]he would have to write it.
Copying from the archives does not amount to "making" in my book.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
On May 28, 3:02 pm, A2 <aaga...@gmail.comwrote:
How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of
variables???
var arr=['a','b','c','d','e','f']
alertRandomItemInArray(arr)
function alertRandomItemInArray(arr){
return arr[Math.round(arr.length*Math.random())]
}
scripts.contact said:
> On May 28, 3:02 pm, A2 <aaga...@gmail.comwrote:
>How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of variables???
var arr=['a','b','c','d','e','f']
alertRandomItemInArray(arr)
function alertRandomItemInArray(arr){
return arr[Math.round(arr.length*Math.random())] }
When choosing between more than two items, don't use
Math.round(). It will only select the first and the
last item half as often as each of the other items.
To the original poster, before asking questions in a
technical newsgroup, look through the recent articles
to see if any of them point you to the FAQ.
Your question is addressed there: http://www.jibbering.com/faq/#FAQ4_22
--
In comp.lang.javascript message <11**********************@i38g2000prf.go
oglegroups.com>, Tue, 29 May 2007 05:40:42, scripts.contact
<sc*************@gmail.composted:
>On May 28, 3:02 pm, A2 <aaga...@gmail.comwrote:
>How would i make a script that would pick a random variable
ex. I would have and array and the script would pick one of variables???
var arr=['a','b','c','d','e','f']
alertRandomItemInArray(arr)
function alertRandomItemInArray(arr){
return arr[Math.round(arr.length*Math.random())] }
Your arr.length = 6. Math.round(6*math.random()) will give 0 (8%), 1-5
(17% each) and 6 (8%). When it gives 6 the return value will be
_undefined_.
Before posting "answer"s, please read the FAQ and test your code.
--
(c) John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rahul Anand |
last post by:
Hi all,
I am trying to fetch 5 records, randomly picked and in random order
from a MySQL table (MySQL version > 3.23).
I wrote my SQL Query as
SELECT name,id FROM tablename WHERE active =...
|
by: Christopher Brandsdal |
last post by:
Hi!
I'm not sure, but this might be a question not right for this group.
Problem:
I have a sql statement that selects all rows with a sertain criteria, an
display it on a page.
What I need...
|
by: Wim Roffil |
last post by:
Hi,
When I do a select with a limit I get always the same records. Usually this
is the desidered effect.
But now I want to do a random select. So every time I do a select I should
get a...
|
by: Joseph Shraibman |
last post by:
Is there a way to get random rows besides ORDER BY random()? The problem with ORDER BY
random() is that is has to get all the rows from the table before the results are returned.
...
|
by: Jean-Francois.Doyon |
last post by:
Hello,
I'm trying to retrieve a limited number of random rows, and order them by a
column, and am not having any luck with that last part:
SELECT * FROM tablename ORDER BY random(), id LIMIT...
|
by: Ini |
last post by:
Hi,
Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?
I was thinking about doing a recordcount of the recordset, then find at
random the...
|
by: Arnau Rebassa |
last post by:
Hi everybody,
I'm doing the following query:
select * from messages order by random() limit 1;
in the table messages I have more than 200 messages and a lot of times, the
message retrieved...
|
by: Kari Lavikka |
last post by:
Hi!
I have to select a random row from a table where primary key isn't
continuous (some rows have been deleted). Postgres just seems to do
something strange with my method.
--
-- Use the...
|
by: darrel |
last post by:
I can grab a random number in vb.net like this:
Dim RandomClass As New Random
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(1, 26)
However, what I want is a random number. Short...
|
by: Jimmy |
last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far:
<%
Dim oConn, oRS, randNum
Randomize()
randNum = (CInt(1000 * Rnd) + 1) *...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |