Random Number Picker

  • Thread starter Thread starter jerryyang_la1
  • Start date Start date
J

jerryyang_la1

Anyone know of a Random Number Picker ?

I have a list of numbers.. and I want a program to randomly pick
numbers from it..

The list is as:

4546546
1516154
8834819
9853487

Any ideas ??

Thanks

Jez
 
Anyone know of a Random Number Picker ?

I have a list of numbers.. and I want a program to randomly pick
numbers from it..

The list is as:

4546546
1516154
8834819
9853487

A bit of Javascript can do that. Copy and paste this into a text editor:

<html>
<head><title>Random Number Picker</title>
<script type="text/javascript">
nums=[4546546,1516154,8834819,9853487];
function getRand(n){
return Math.floor(Math.random()*n);
}
function pickNum(){
out1.value=nums[getRand(nums.length)];
}
function shuffle(){
var tmp;
var tmp2;
for(var i=0;i<5;i++){
for(var j=0;j<nums.length;j++){
tmp=nums[j];
tmp2=getRand(nums.length);
nums[j]=nums[tmp2];
nums[tmp2]=tmp;
}
}
out2.value=nums.join('\n');
}
function setUp(){
out1=document.forms['f1'].elements['t1'];
out2=document.forms['f2'].elements['t2'];
}
onload=setUp;
</script>
</head>
<body>
<form name="f1">
<input name="t1" type="text" />
<input type="button" value="Pick a Number" onclick="pickNum()" />
</form><br />
<form name="f2">
<textarea name="t2" rows="10"></textarea>
<input type="button" value="Shuffle Numbers" onclick="shuffle()" />
</form>
</body>
</html>

Save it with a name dot html (example - randompicker.html). Open the
saved file with your browser and click the buttons.

At the top of the script there's an array called nums. Replace the
numbers between the square brackets with the numbers you want to work
with, separated by commas (example - nums=[3,5,623,17,99,7645])
 
Thanks for that..

But the list has about 150 numbers on it..

Any Other Ideas ?

Cheers

Jez

Anyone know of a Random Number Picker ?

I have a list of numbers.. and I want a program to randomly pick
numbers from it..

The list is as:

4546546
1516154
8834819
9853487

A bit of Javascript can do that. Copy and paste this into a text editor:

<html>
<head><title>Random Number Picker</title>
<script type="text/javascript">
nums=[4546546,1516154,8834819,9853487];
function getRand(n){
return Math.floor(Math.random()*n);
}
function pickNum(){
out1.value=nums[getRand(nums.length)];
}
function shuffle(){
var tmp;
var tmp2;
for(var i=0;i<5;i++){
for(var j=0;j<nums.length;j++){
tmp=nums[j];
tmp2=getRand(nums.length);
nums[j]=nums[tmp2];
nums[tmp2]=tmp;
}
}
out2.value=nums.join('\n');
}
function setUp(){
out1=document.forms['f1'].elements['t1'];
out2=document.forms['f2'].elements['t2'];
}
onload=setUp;
</script>
</head>
<body>
<form name="f1">
<input name="t1" type="text" />
<input type="button" value="Pick a Number" onclick="pickNum()" />
</form><br />
<form name="f2">
<textarea name="t2" rows="10"></textarea>
<input type="button" value="Shuffle Numbers" onclick="shuffle()" />
</form>
</body>
</html>

Save it with a name dot html (example - randompicker.html). Open the
saved file with your browser and click the buttons.

At the top of the script there's an array called nums. Replace the
numbers between the square brackets with the numbers you want to work
with, separated by commas (example - nums=[3,5,623,17,99,7645])
 
Thanks for that..

But the list has about 150 numbers on it..

Any Other Ideas ?

If your numbers are listed like you posted above, eg:

4546546
1516154
8834819
9853487

you can copy and paste it into the textbox in this changed script (no
harm if you choose not to use this btw, I'm just having a bit of fun
banging out a little javascript :) )

<html>
<head><title>Random Number Picker</title>
<script type="text/javascript">
nums=[];
function getRand(n){
return Math.floor(Math.random()*n);
}
function pickNum(){
if(!nums.length)makeArray();
out1.value=nums[getRand(nums.length)];
}
function shuffle(){
if(!nums.length)makeArray();
var tmp;
var tmp2;
for(var i=0;i<5;i++){
for(var j=0;j<nums.length;j++){
tmp=nums[j];
tmp2=getRand(nums.length);
nums[j]=nums[tmp2];
nums[tmp2]=tmp;
}
}
out2.value=nums.join('\n');
}
function makeArray(){
nums=in1.value.replace(/^\s+|\s+$/g,'').split('\n');
}
function setUp(){
in1=document.forms['f0'].elements['t0'];
out1=document.forms['f1'].elements['t1'];
out2=document.forms['f2'].elements['t2'];
}
onload=setUp;
</script>
</head>
<body>
<form name="f0">
<textarea name="t0" rows="10" onclick="if(this.value==this.defaultValue)
{this.value=''}">
Paste numbers here</textarea>
</form>
<form name="f1">
<input name="t1" type="text" />
<input type="button" value="Pick a Number" onclick="pickNum()" />
</form><br />
<form name="f2">
<textarea name="t2" rows="10"></textarea>
<input type="button" value="Shuffle Numbers" onclick="shuffle()" />
</form>
</body>
</html>
 
Go to http://free.hostdepartment.com/b/bangagong/shuffler.html and download
the page. I think you need javascript enabled for it to work. This resulted
from a request for a program that would shuffle a list of URLs. It can also
be used to shuffle a list of numbers etc.

Alternatively (the hard way!), make 150 (or whatever) blank files titled
with the numbers and put them in a folder. Then use Ctrl-R in Tracker to
randomise the list. I use this method to make lottery selections with 49
files.
http://www.trackerv3.com/download.htm

===

Frank Bohan
¶ You're never alone with a clone.
 
In message said:
Anyone know of a Random Number Picker ?

I have a list of numbers.. and I want a program to randomly pick
numbers from it..

The list is as:

4546546
1516154
8834819
9853487

Any ideas ??

Put the numbers in a spreadsheet column A. Fill column B with random
numbers, then sort the whole sheet by column B. Select how ever many
numbers you want from the top of the list. It should be fairly simple to
write a macro to automate this.
 
Anyone know of a Random Number Picker ?

I have a list of numbers.. and I want a program
to randomly pick numbers from it..

The list is as:

4546546
1516154
8834819
9853487

Jerry ....

You might consider the Python language ....

http://www.python.org

A simple Python installer for Windows is available
from ActiveState.Com ....

http://www.activestate.com/Products/ActivePython/


8 lines of Python code will read a list of numbers,
1 number per line as you've shown above, and select
a random number from that list ....

Pass the path to the text file that contains
the number list to the program as an argument
on the command line ....

python random_choice.py /path/to/number_list.txt

Copy/Paste the following code
and save as random_choice.py ....

# -------------------------------------------------------

import sys

import random

path_in = sys.argv[ 1 ]

file_in = file( path_in , 'r' )

candidates = file_in.readlines()

this_choice = random.choice( candidates )

print "\n Random Choice .... %s " % ( this_choice )

file_in.close()

# -------------------------------------------------------
 
Alternatively (the hard way!), make 150 (or whatever) blank files titled
with the numbers and put them in a folder. Then use Ctrl-R in Tracker to
randomise the list. I use this method to make lottery selections with 49
files.
http://www.trackerv3.com/download.htm

Ouch!

Generate a random number between 1 and 49 and read that line from a
single text file.

Alternatively, read the file to get the line count and generate the
number from that.
 
Back
Top