# Generating A Random Between 2 Numbers?

May 11, 2010

I'll get to the point, I'm a noob I'm using greasemonkey for a certain website. Basically, I'm using gm to refresh the page after a certain time, I was however wondering, If I can set it to a random number between 2 specific times?

The code I'm using atm is setTimeout(function() { document.location.reload(); } , 10000); I know I have to use math.random, well, I think I do. But I'm not sure how to do it between 2 certain times? So to summarise, I'm trying to refresh a page at any given random time between say 5-10 minutes.

## Generating Random Number

Feb 28, 2006

In the forum, it usually talked about generating a number between 1 or 0 to that certain value using something like Math.round(Math.random() * 200); or Math.floor(Math.random() * 200);

But what do you do if you want to generate a number between 201 and 400.

## Random Number Generating

Aug 27, 2006

I run a random number generating service for a RPG message board I go to, and my website generates only numbers from 1-100. How could I script this so that the user can get random numbers between 1-X?

## Generating Random Images With No Repeats?

Jan 22, 2009

I want a certain amount of image spots to show a certain set of images (specifically 8) in a random order every time the page is refreshed. I do not want the images to be repeated, however. The solution I came up with was to create an array and generate a number one to eight and then compare that number to the numbers previously in the array, and if it matched one that was previously generated, to generate a new number and then compare it. This continues until i have an array of the numbers 1-8 in a random order.

var imgs=new Array(8);
for(i in imgs)
{
function generate()
{
return Math.floor(1+Math.random()*8);

[Code]...

This does not strike me as the most efficient way to go about this. If someone has a better solution,

## Resolved Having Generating Random Text?

Aug 9, 2009

New to JS, and not too good at it. Trying to take some prewritten code and add script that displays some random text. Having trouble with assignment. Instructions are to replace a section of the file I am given with a script element. In the script element I am suppose to declare a variable named tipNum equal to a random integer between 1 and 10 returned by the randInt() function (which I made and have shown below). Then I am suppose to use a series of document.write() methods to write the following HTML code into the page:

<h1>Random Tip<br />title</h1>
<p>tip</p>

(Where "title" is the title of the random text as generated by the tipTitle() function from a external file, and which I did not make; and "tip" is the text of the random tip as genereated by the tipText() function, which is also from the external file, and not made by me) My code for the randInt() function is

function randInt(lower, upper) {
var size = ++(upper - lower);
var randValue = Math.floor(lower + size*Math.random());
}

The script I made to display the HTML code is

[Code]...

I am getting nothing on my page where the random text should be.

## Generating Random Image Using RandomOneOf?

May 18, 2011

For a computer science class homework assignment I need to create a page where an image changes randomly when a button is clicked. This is what I have so far, nothing happens when button is clicked. I need the button to randomly return one of the five images described in the emotions function. Please help, I sorely need it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
<html xmlns="http://www.w3.org/1999/xhtml">
<title> Picture Fun </title>
<style type="text/css">
body {font-family: verdana; margin-top: 1in}

[Code]...

## Sum Of 10 Random Numbers?

Oct 12, 2010

I'm using a forLoop to generate 10 random numbers, how would I go about added them all together? code...

## Unique Random Numbers

Jul 22, 2002

<script language="JavaScript">
// Unique Random Numbers Picker
// By Premshree Pillai

var numArr = new Array("0","1","2","3","4","5","6","7","8","9"); // Add elements here
var pickArr = new Array(); // The array that will be formed
var count=0;
var doFlag=false;
var iterations=0;

function pickNums(nums)
{
iterations+=1;
var currNum = Math.round((numArr.length-1)*Math.random());
if(count!=0)
{
for(var i=0; i<pickArr.length; i++)
{
if(numArr[currNum]==pickArr[i])
{
doFlag=true;
break;
}
}
}
if(!doFlag)
{
pickArr[count]=numArr[currNum];
document.write('<b>' + numArr[currNum] + '</b> <font color="#808080">|</font> ');
count+=1;
}
if(iterations<(numArr.length*3)) // Compare for max iterations you want
{
if((count<nums))
{
pickNums(nums);
}
}
else
{
}
}

pickNums(5); // Call the function, the argument is the number of elements you want to pick.
// Here we pick 5 unique random numbers.

## Unique Random Numbers II

Aug 22, 2002

This script is a slightly modified version of "Unique Random Numbers". In this script it becomes easier to implement more than one instances of "Picking Unique Random Numbers".

This JavaScript picks up a number of unique random elements from an array.

For example; if you have an array myArray consisting of 10 elements and want to pick 5 unique random elements. Suppose initially myArray[3] is picked randomly, then myArray[3] should not be picked again.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title>Unique Random Numbers II</title>
<script language="JavaScript">
// Unique Random Numbers II
// -Picks a number of unique random numbers from an array
// By Premshree Pillai
// http://www.qiksearch.com, http://javascript.qik.cjb.net

function pickNums(nums, numArr, pickArr, count, doFlag, iterations)
{
iterations+=1;
var currNum = Math.round((numArr.length-1)*Math.random());
if(count!=0)
{
for(var i=0; i<pickArr.length; i++)
{
if(numArr[currNum]==pickArr[i])
{
doFlag=true;
break;
}
}
}
if(!doFlag)
{
pickArr[count]=numArr[currNum];
document.write('<b>' + numArr[currNum] + '</b> <font color="#808080">|</font> ');
/* Modify above line for a different format output */
count+=1;
}
if(iterations<(numArr.length*3)) // Compare for max iterations you want
{
if((count<nums))
{
pickNums(nums, numArr, pickArr, count, doFlag, iterations);
}
}
else
{
}
}
</script>
<body bgcolor="#FFFFFF">

<!--BEGIN BODY SECTION CODE-->
<script language="JavaScript">
var numArr1 = new Array("0","1","2","3","4","5","6","7","8","9"); // Add elements here
var pickArr1 = new Array(); // The array that will be formed
var count1=0;
var doFlag1=false;
var iterations1=0;

pickNums(5, numArr1, pickArr1, count1, doFlag1, iterations1); // Call the function, the argument is the number of elements you want to pick.
// Here we pick 5 unique random numbers
</script>
<!--END BODY SECTION CODE-->

</body>
</html>

## Getting Three Unique Random Numbers?

Apr 13, 2009

My Name is Tom I am from the UK and I am (for my own entertainment and learning) creating a dvd indexing web application to sort and catagorize my dad's dvd collection. On the homepage for this website I have dynamically (using JS) appended 3 image elements which contain the images of dvd box art at "x by 225" pixel dimensions i.e. when I resize the dvd box art they all have to be 225 pixels in height and constrain to the necessary width in contrast to the height. Now that the images are working, I now want them to be randomized so 3 unique box art images are displayed everytime the page is refreshed. So far my script is:

Code:

// Image Rotation Javascript
function imageRotation()
{

[Code].....

Problem with this is that sometimes I get results from the random number generation that are non-unique i.e. sometimes random_number1, random_number2 and random_number3 yield: 3,3 and 11 etc. I need to make it so that you never get such clashes or it will show 2 or more identical images on the homepage. How can I change the random number generators to achieve this?

how to plug the imgObj into the image elements as to use the preloaded images instead (at the moment their just hard coded.)

## Adding 3 Different Random Numbers For Blackjack / 21?

Oct 19, 2009

I would like to create a Blackjack style game for one of my high school programming classes. I can generate 3 different random numbers and use these random numbers to display an image with that number on it.

How do I add the 3 separately generated numbers together to show the total??

Here is my code so far. Specifically I would like to add the myNumber1(), myNumber2() and myNumber3() results together.

<html>
<title>Play 21</title>
<script language="javascript">
function myNumber1(){

[Code]....

## Clone Element - After Row 10 Random Numbers

Nov 30, 2011

I have a form wich has a add/remove row button, this so the visitor can select multiple sets of data. All is fine and is being submitted via PHP.

Only problem is from number 10 and up, i am getting strange random numbers in the new rows that are added in their name. Like 1111 (instead of 11), 122222 (instead of 12). And because of this, every row from 10 and up won't be send through php, giving this random effect.

The full form can be viewed: [url]

The code i use for my Clone Element is:

## Generate Random Numbers Without Repeating [js]?

May 14, 2011

I got this code and it generates random numbers but with repeating code...

## Multiple Array And Random Numbers ?

Nov 10, 2010

I have a quick question with multiple array and random numbers. If i generate my random numbers in one array, how would i take a selection of those numbers and put them in another array?

Ex: array 1: 25, 34, 38, 40, 22, 49

Want to move numbers between 30 and 50 to another array.

array 2: 34, 38, 40, 49

Is it as simple as for loops and if statements setting the conditions? do i use a sorting method? (selection? bubble?)

## Dynamically Re-generate Random Numbers In A Table?

Nov 19, 2009

I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.[code]...

## Using For Loop To Give An Array 10 Random Numbers?

Feb 18, 2009

I am working on a problem that wants me to use a for loop to give an array a random number for each of it's elements (total of 10) and then using a second loop to add them up and display the result.

<script type="text/javascript">
var sum;
var i=0;

[code]....

## Creating Cookie To Store Random Numbers?

Apr 5, 2006

How do I create a cookie for storing a random number in it.

## How To Dynamically Re-generate Random Numbers In A Table

Nov 19, 2009

I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.code...

## Creating A Code To Search A Series Of Random Numbers

Oct 28, 2011

I am trying to create a javascript code in which I prompt the user for a number (an integer from 0 to 100) to search for, then search a function with the number they entered and then display whether the number was found, and if found, a location where it can be found within the list.

<html>
<body>

[Code]....

## Math Function - Task To Generate Two Random Numbers

Jun 21, 2011

I've got my code, and the task is to generate two random numbers, the user then inputs an answer for them added together, then the program checks the answer and displays either "correct" or "wrong". Here's some of my code:

Code:
<HTML>
<TITLE>Assessment Task 3 : Rohan Gardiner</TITLE>
<SCRIPT LANGUAGE ="JavaScript">
function maths(){
var response;
response = "correct";
} else {
response = "wrong";
} document.questions.result.value = response ;
} function randoms() {
rndNum = Math.random();
Num = rndNum*20;
Num1=rndNum*10
document.write(Math.round(Num)+"+"+ Math.round(Num1));
document.write(Math.round(Num) + Math.round(Num1)); }
<h1 align="center">Rohan Gardiner Assessment Task 3</h1>
<FORM NAME = "questions">
<SCRIPT Language=JavaScript> randoms(); </script>
=
<INPUT TYPE = "textbox" NAME = "answer" > <BR>
<INPUT NAME = "dobutton" TYPE = "button" Value = "check" onClick= "maths()">
<INPUT TYPE = "textbox" NAME = "result" >
</BODY></HTML>

## Generate Random Numbers 0-8 To Use To Access Array Indices

May 5, 2009

I'm trying to generate random numbers 0-8 to use to access array indices.[code]Every once in a while, I'm getting a -1 in my console log. I read on a site that this line:[code]will generate a number between 0 and 10 (so 1-9).How is -1 being generated?

## Include Numbers And Alphabets Instead Of Numbers Only?

Apr 7, 2009

I need to modify the script showed at: [URL]

Right now it allows entering "numbers only", I need it so that it allows numbers and alphabets only, no special characters or spaces.

And yes, one more question, does the first part of the code need to be added in the <head> of the document or <body> ?

The code at the above URL is as follows:

<script type="text/javascript">
// initialise variable to save cc input string
var cc_number_saved = "";
</script>

[Code].....

## Random Photo + Rotation Query - Continue From The Random Image And Change To The Next Every 3 Seconds?

Aug 31, 2011

I'm trying to use Javascript to have an array of images that load randomly AND work in a slideshow manner so change every 3 seconds (in a logical order). The code I have below presents a random image but how do I get them to continue from the random image and change to the next every 3 seconds?

<script language="JavaScript">
images = new Array(3);
images[0] = "<a href = 'photo1.html'><img src='images/photo1.jpg' alt='Photo 1'></a>";
images[1] = "<a href = 'photo2.html'><img src='images/photo2.jpg' alt='Photo 2'></a>";
images[2] = "<a href = 'photo3.html'><img src='images/photo3.jpg' alt='Photo 3'></a>";
[Code]...

## Generating <b> Tag By One Click

Dec 23, 2003

Let's suppose a user enters his message " My name is John" in a textarea. and he likes to modify by adding <b> tag before the word "John" after he enters "My name is John".

In order to add <b> tag in front of the word "John", he should put his mouse before "John" and enter <b>.
but instead of entering <b>, I like to make the user to click the button "<b>", then <b> is automatically created just before the word "John" in the textarea.

Of course </b> will be needed later, but forget about </b> for simplification.

In short, I like to make the button "<b>" , in order to add <b> tag in front of "John" after entering "My name is John."

## Prevent Repeating In A Random (Math.random) Array?

Aug 6, 2009

I've looked for a solution to this issue, but it seems like a little different scenario than other situations. I made a system for generating friend requests on Facebook. I have a grid that is 6 x 3, for a total of 18 cells. Each cell has a picture in it, and the picture is linked to the Facebook friend request page. My problem is that since each cell is populated at random from the array, I'm getting lots of repeats. For example, some picutures are in 5 cells, and some are in none. I'm trying to figure out how to make it so that once a picture is used once in the grid, it does not get used again in the same grid.I still want every cell filled at random on each page load, I just want to prevent the repeating.

Here's my current code:
<script type="text/javascript">
var vip_list=new Array(

[Code]...

## Generating Thumbnails Of A Page

Sep 17, 2005

Is there anyway to rescale a whole page homogeneously, so that
is looks like a thumbnail?