Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Requests

Random Number generator

Author Message
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Thu Jun 01, 2006 - 2:21 am    Post subject: Random Number generator Reply with quote

I need a widget that will give me a nine digit random number where each digit is unique and only 1 to 9 are used. NO "0"

for a string

"123456789"
"627138549"
"987654321"

If I can have all possible nine digit combinations where no 2 digits in the numbers are repeated.

NO NUMBERS LIKE "643389649"

Must have all 9 digits 1 to 9 in the numbers.

A delete used numbers would be good. Very Happy

Thanking you in advance for any help you can give me.
View user's profile Send private message Send e-mail Visit poster's website Widgets
gnome
Administrator


Joined: 26 Sep 2004
Posts: 145

Posted: Fri Jun 02, 2006 - 11:56 pm    Post subject: Reply with quote

Here's the signifigant half of the code:
Code:

<script>
function makeMyString()  // returns string of permutated 123456789
{

x=new Array("1","2","3","4","5","6","7","8","9");
cnt=x.length;
for(i=0; i<cnt; i++)
{
rand=Math.floor(Math.random()*cnt);
tmp=x[i]; x[i]=x[rand]; x[rand]=tmp;
}
genString = x.join("");
return genString;

}
</script>
View user's profile Send private message Widgets
billyFUN



Joined: 03 Jun 2006
Posts: 4
Location: Philadelphia

Posted: Sat Jun 03, 2006 - 7:03 am    Post subject: Reply with quote

I was fooling around with that Dashcode app that Apple leaked (it looks like it'll be a great program if they can fix all the bugs in it). Anyway, I saw your post and I figured this would be a relatively easy thing to try to do.

So here you go: http://toppertree.org/z-junk/numba.wdgt.zip


Some notes about the widget:
Click the round arrow to generate a number.
Click the number and it'll be copied to your clipboard.
I did the math and there are 362,880 possible numbers, but, because of the way it's coded --with a looping 'if' comparison, the widget will probably become unusably slow after a few thousand numbers have been selected.
There's a reset button on the back that will delete the list of previously generated numbers (which should cure any slowness).

Oh, and it ain't too pretty. Wink
View user's profile Send private message Send e-mail Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Sat Jun 03, 2006 - 9:51 pm    Post subject: Full list Reply with quote

That is fantastic and I can use that but I need a full listing if that can be done. I am happy to run it for days if I have to. But there must be a finite list.

gnome wrote:
Here's the signifigant half of the code:
Code:

<script>
function makeMyString()  // returns string of permutated 123456789
{

x=new Array("1","2","3","4","5","6","7","8","9");
cnt=x.length;
for(i=0; i<cnt; i++)
{
rand=Math.floor(Math.random()*cnt);
tmp=x[i]; x[i]=x[rand]; x[rand]=tmp;
}
genString = x.join("");
return genString;

}
</script>
[list=][/list]
View user's profile Send private message Send e-mail Visit poster's website Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Mon Jun 05, 2006 - 6:59 pm    Post subject: How do you get a full list? All 362,880 numbers Reply with quote

How do you get a full list? All 362,880 (this number looks a bit small) numbers?

I couldn't get a list on the clipboard.

Can anyone show me how to generate a full list.

Thanking you for the terrific help you have given so far.
View user's profile Send private message Send e-mail Visit poster's website Widgets
billyFUN



Joined: 03 Jun 2006
Posts: 4
Location: Philadelphia

Posted: Mon Jun 05, 2006 - 8:53 pm    Post subject: Reply with quote

Here's a list of the possible number combinations http://toppertree.org/z-junk/numbers1.txt.zip. It's a 3.5MB tab-delimited text file (1MB zipped).
I made the list with a PHP script (that took a few hours to run). The script just iterates every number from 123456789 to 987654321 comparing each number's individual digits to see if any repeat.
Code:

for ($i=123456789; $i<=987654321; $i++){
   $x = "$i";
   if (   
      (strpos($x, "0")===false) &&
      (substr($x, 0, 1) != substr($x, 1, 1)) &&
      (substr($x, 0, 1) != substr($x, 2, 1)) &&
      (substr($x, 0, 1) != substr($x, 3, 1)) &&
      (substr($x, 0, 1) != substr($x, 4, 1)) &&
      (substr($x, 0, 1) != substr($x, 5, 1)) &&
      (substr($x, 0, 1) != substr($x, 6, 1)) &&
      (substr($x, 0, 1) != substr($x, 7, 1)) &&
      (substr($x, 0, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 1, 1) != substr($x, 2, 1)) &&
      (substr($x, 1, 1) != substr($x, 3, 1)) &&
      (substr($x, 1, 1) != substr($x, 4, 1)) &&
      (substr($x, 1, 1) != substr($x, 5, 1)) &&
      (substr($x, 1, 1) != substr($x, 6, 1)) &&
      (substr($x, 1, 1) != substr($x, 7, 1)) &&
      (substr($x, 1, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 2, 1) != substr($x, 3, 1)) &&
      (substr($x, 2, 1) != substr($x, 4, 1)) &&
      (substr($x, 2, 1) != substr($x, 5, 1)) &&
      (substr($x, 2, 1) != substr($x, 6, 1)) &&
      (substr($x, 2, 1) != substr($x, 7, 1)) &&
      (substr($x, 2, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 3, 1) != substr($x, 4, 1)) &&
      (substr($x, 3, 1) != substr($x, 5, 1)) &&
      (substr($x, 3, 1) != substr($x, 6, 1)) &&
      (substr($x, 3, 1) != substr($x, 7, 1)) &&
      (substr($x, 3, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 4, 1) != substr($x, 5, 1)) &&
      (substr($x, 4, 1) != substr($x, 6, 1)) &&
      (substr($x, 4, 1) != substr($x, 7, 1)) &&
      (substr($x, 4, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 5, 1) != substr($x, 6, 1)) &&
      (substr($x, 5, 1) != substr($x, 7, 1)) &&
      (substr($x, 5, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 6, 1) != substr($x, 7, 1)) &&
      (substr($x, 6, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 7, 1) != substr($x, 8, 1))
      ){
         print $x . "<br />";

      }
}
View user's profile Send private message Send e-mail Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Mon Jun 05, 2006 - 10:42 pm    Post subject: Full list Reply with quote

This is GREAT.

Thank you very much.

billyFUN wrote:
Here's a list of the possible number combinations http://toppertree.org/z-junk/numbers1.txt.zip. It's a 3.5MB tab-delimited text file (1MB zipped).
I made the list with a PHP script (that took a few hours to run). The script just iterates every number from 123456789 to 987654321 comparing each number's individual digits to see if any repeat.
Code:

for ($i=123456789; $i<=987654321; $i++){
   $x = "$i";
   if (   
      (strpos($x, "0")===false) &&
      (substr($x, 0, 1) != substr($x, 1, 1)) &&
      (substr($x, 0, 1) != substr($x, 2, 1)) &&
      (substr($x, 0, 1) != substr($x, 3, 1)) &&
      (substr($x, 0, 1) != substr($x, 4, 1)) &&
      (substr($x, 0, 1) != substr($x, 5, 1)) &&
      (substr($x, 0, 1) != substr($x, 6, 1)) &&
      (substr($x, 0, 1) != substr($x, 7, 1)) &&
      (substr($x, 0, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 1, 1) != substr($x, 2, 1)) &&
      (substr($x, 1, 1) != substr($x, 3, 1)) &&
      (substr($x, 1, 1) != substr($x, 4, 1)) &&
      (substr($x, 1, 1) != substr($x, 5, 1)) &&
      (substr($x, 1, 1) != substr($x, 6, 1)) &&
      (substr($x, 1, 1) != substr($x, 7, 1)) &&
      (substr($x, 1, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 2, 1) != substr($x, 3, 1)) &&
      (substr($x, 2, 1) != substr($x, 4, 1)) &&
      (substr($x, 2, 1) != substr($x, 5, 1)) &&
      (substr($x, 2, 1) != substr($x, 6, 1)) &&
      (substr($x, 2, 1) != substr($x, 7, 1)) &&
      (substr($x, 2, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 3, 1) != substr($x, 4, 1)) &&
      (substr($x, 3, 1) != substr($x, 5, 1)) &&
      (substr($x, 3, 1) != substr($x, 6, 1)) &&
      (substr($x, 3, 1) != substr($x, 7, 1)) &&
      (substr($x, 3, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 4, 1) != substr($x, 5, 1)) &&
      (substr($x, 4, 1) != substr($x, 6, 1)) &&
      (substr($x, 4, 1) != substr($x, 7, 1)) &&
      (substr($x, 4, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 5, 1) != substr($x, 6, 1)) &&
      (substr($x, 5, 1) != substr($x, 7, 1)) &&
      (substr($x, 5, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 6, 1) != substr($x, 7, 1)) &&
      (substr($x, 6, 1) != substr($x, 8, 1)) &&
      
      (substr($x, 7, 1) != substr($x, 8, 1))
      ){
         print $x . "<br />";

      }
}
View user's profile Send private message Send e-mail Visit poster's website Widgets
purvisa



Joined: 21 Jul 2005
Posts: 182
Location: Kirkland, WA

Posted: Tue Jun 06, 2006 - 7:58 pm    Post subject: Re: How do you get a full list? All 362,880 numbers Reply with quote

The math is relatively simple, by the way, as it is basic combinatorics. Think about two unique items and their possible orders: AB, and BA. This is 2! (2*1).

Extend it to three numbers, and you get this: ABC, ACB, BAC, BCA, CAB, CBA. This is 3! (3*2*1).

This means that for N unique items, the number of ordered sequences will be equal to N!, which can be expressed as this:

N*(N-1)...(N-(N-1))

As noted earlier, that yields 362,880 combinations.

This looks like a Sudoku-related piece of code, and if it is, there are a few more things to consider about the math. In general, as soon as you have fixed a number's position in a column, row, or box, you have altered the number of combinations for that column, row, or box. In short, your N, once you place one number, becomes N-1.

Furthermore, all variations that are prevented because of placement of the same number on one of the other axes eliminate all possible results that place that number (or those numbers) into that space, though this is not (in most cases) the same as reducing N.

Finally, as soon as one row (or one column or one box) of numbers is complete, the other axes are all limited by what is fixed, reducing severity of the calculation to generate or solve the puzzle.

Lawrence wrote:
How do you get a full list? All 362,880 (this number looks a bit small) numbers?

I couldn't get a list on the clipboard.

Can anyone show me how to generate a full list.

Thanking you for the terrific help you have given so far.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Tue Jun 06, 2006 - 10:03 pm    Post subject: Re: How do you get a full list? All 362,880 numbers Reply with quote

G'day Purvisa, thank you for this extra information, it all helps me understand what I am dealing with. By the way, its not a Sudoku related piece of code, its for my Key90 puzzles. I have to do some reverse engineering as my old CPM basic code from 1984-6 is now unreadable. And so are the backup tapes. No hard copy anymore. Tens of thousands of the puzzles printed on old dot-metrics machines and the old fan feed paper.

You can see my puzzles in the Sydney Morning Herald on Monday, Wednesday and Fridays as Unisol Puzzles. Or at www.key90.com

As I am getting close to retirment I need to get the puzzle into a few publications or I will not have an income in my old age.

We are dealing with a 4 X 4 matrix puzzle here.

purvisa wrote:
The math is relatively simple, by the way, as it is basic combinatorics. Think about two unique items and their possible orders: AB, and BA. This is 2! (2*1).

Extend it to three numbers, and you get this: ABC, ACB, BAC, BCA, CAB, CBA. This is 3! (3*2*1).

This means that for N unique items, the number of ordered sequences will be equal to N!, which can be expressed as this:

N*(N-1)...(N-(N-1))

As noted earlier, that yields 362,880 combinations.

This looks like a Sudoku-related piece of code, and if it is, there are a few more things to consider about the math. In general, as soon as you have fixed a number's position in a column, row, or box, you have altered the number of combinations for that column, row, or box. In short, your N, once you place one number, becomes N-1.

Furthermore, all variations that are prevented because of placement of the same number on one of the other axes eliminate all possible results that place that number (or those numbers) into that space, though this is not (in most cases) the same as reducing N.

Finally, as soon as one row (or one column or one box) of numbers is complete, the other axes are all limited by what is fixed, reducing severity of the calculation to generate or solve the puzzle.

Lawrence wrote:
How do you get a full list? All 362,880 (this number looks a bit small) numbers?

I couldn't get a list on the clipboard.

Can anyone show me how to generate a full list.

Thanking you for the terrific help you have given so far.
Very Happy Very Happy
View user's profile Send private message Send e-mail Visit poster's website Widgets
purvisa



Joined: 21 Jul 2005
Posts: 182
Location: Kirkland, WA

Posted: Wed Jun 07, 2006 - 2:55 am    Post subject: Reply with quote

With a 4x4 grid, the math gets a little more interesting. In that case, you are dealing with a Choose function, which is how basic single-pool lottery odds are calculated. Here's a look at a lottery that would be great to play, involving only 30 numbers and 5 selections:

You have a ticket with the boring numbers 1, 2, 3, 4, and 5. In order to win, those five numbers must be drawn, in any order, from a pool of 30 numbers. First we perform a basic Choose function 30C5, which is a limited form of the formula in my earlier post, in that it is 30*29*28*27*26 (five iterations of multiplication, beginning with 30 and reducing by one each time, generalized as N*(N-1) . . . (N-(R-1)), where R is the number of randomly selected objects). This calculation yields 17,100,720. Now we know how many five-number combinations exist.

Next, we need to consider how many ways five specific numbers could be drawn and arranged. Since there are five unique objects, we simply calculate 5!, or 5*4*3*2*1, which gives us 120.

We finally divide 120 by 12,100,720 to get our chances of winning, but since that is an obscenely small decimal, let's just simplify the farction by dividing both by 120. That gives us a 1 in 142,506 chance of winning the lottery.

This can also be calculated as a series of dependent single probabilities. The first ball has a 5 in 30 chance of being good for us. If that works, the second is 4 in 29, the third is 3 in 28, the fourth is 2 in 27, and the last is 1 in 26. As you can see, that will just create a 120 in 142,506 chance, just expressed as a fraction rather than independent numbers (which, by dint of division, become a fraction anyway).

This means that there are 9C4 possible rows (or columns that meet the conditions of a Key 90 puzzle. This means there are only 3024 possibilities, but when you put together the possible row-column combinations, the number of puzzles proves to be quite high (no, I won't calculate that right now—I teach English, not math).

Writing a program to generate random Key 90 puzzles should not be too difficult. Indeed, it may well take only a day or two, once one is coded up, to calculate all possible general forms (in which letters are not assigned numerical value, but the possible grids are all computed, which is far smaller than the total number of puzzles. From there, all possible letter changes (switching A for B to create a different appearance for an identical pattern) and all possible number assignment combinations could be computed, the totals worked out, and a huge supply of puzzles prepared. The variation, then, of starting data and the evaluation of relative difficulty should be all that remains when setting them up.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Wed Jun 07, 2006 - 6:10 am    Post subject: Reply with quote

G'day Purvisa, I see you have the bug. Quite a few teachers have used my puzzles here in Australia. It lends its self to play with.

I think it has more to it than Sudoku puzzles and I have data for twenty levels of difficulty the hard ones are loved by teachers, accountants, etc. who hold timed competitions.

purvisa wrote:
With a 4x4 grid, the math gets a little more interesting. In that case, you are dealing with a Choose function, which is how basic single-pool lottery odds are calculated. Here's a look at a lottery that would be great to play, involving only 30 numbers and 5 selections:

You have a ticket with the boring numbers 1, 2, 3, 4, and 5. In order to win, those five numbers must be drawn, in any order, from a pool of 30 numbers. First we perform a basic Choose function 30C5, which is a limited form of the formula in my earlier post, in that it is 30*29*28*27*26 (five iterations of multiplication, beginning with 30 and reducing by one each time, generalized as N*(N-1) . . . (N-(R-1)), where R is the number of randomly selected objects). This calculation yields 17,100,720. Now we know how many five-number combinations exist.

Next, we need to consider how many ways five specific numbers could be drawn and arranged. Since there are five unique objects, we simply calculate 5!, or 5*4*3*2*1, which gives us 120.

We finally divide 120 by 12,100,720 to get our chances of winning, but since that is an obscenely small decimal, let's just simplify the farction by dividing both by 120. That gives us a 1 in 142,506 chance of winning the lottery.

This can also be calculated as a series of dependent single probabilities. The first ball has a 5 in 30 chance of being good for us. If that works, the second is 4 in 29, the third is 3 in 28, the fourth is 2 in 27, and the last is 1 in 26. As you can see, that will just create a 120 in 142,506 chance, just expressed as a fraction rather than independent numbers (which, by dint of division, become a fraction anyway).

This means that there are 9C4 possible rows (or columns that meet the conditions of a Key 90 puzzle. This means there are only 3024 possibilities, but when you put together the possible row-column combinations, the number of puzzles proves to be quite high (no, I won't calculate that right now—I teach English, not math).

Writing a program to generate random Key 90 puzzles should not be too difficult. Indeed, it may well take only a day or two, once one is coded up, to calculate all possible general forms (in which letters are not assigned numerical value, but the possible grids are all computed, which is far smaller than the total number of puzzles. From there, all possible letter changes (switching A for B to create a different appearance for an identical pattern) and all possible number assignment combinations could be computed, the totals worked out, and a huge supply of puzzles prepared. The variation, then, of starting data and the evaluation of relative difficulty should be all that remains when setting them up.


It is amazing the way things have turned out. My Farther was one of the designers of the old radio valves for the first mainframes. I started off with a 16K Micro-bee (cassette loaded) and it was on that Australian computer that Key90 began. We would not program like that to day. I have not programmed anything for a long long time. Now someone can do things in a few days that took years to do in basic and then C and C++ in CPM and had to be tested all the way. And saved to an audio tape. Very Happy
View user's profile Send private message Send e-mail Visit poster's website Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Thu Jun 22, 2006 - 6:40 am    Post subject: 4x4 grid manipulation Reply with quote

G'day Purvisa,
purvisa wrote:
With a 4x4 grid, the math gets a little more interesting.


Yes I agree, one of my problems will be to work out a way of finding out how to move rows and coulombs to find the maximum number of moves possible without repeating a 4x4? As the integrity of the grid is held in tact.

That is to say moving the top row to the bottom etc. All totals remain the same.

purvisa wrote:

Writing a program to generate random Key 90 puzzles should not be too difficult. Indeed, it may well take only a day or two, once one is coded up, to calculate all possible general forms (in which letters are not assigned numerical value, but the possible grids are all computed, which is far smaller than the total number of puzzles. From there, all possible letter changes (switching A for B to create a different appearance for an identical pattern) and all possible number assignment combinations could be computed, the totals worked out, and a huge supply of puzzles prepared. The variation, then, of starting data and the evaluation of relative difficulty should be all that remains when setting them up.


This is so amazing. I would love to see your results.

Had you ever heard of these puzzles?

I think they are great brain food they have so many ways of making people look at what they are looking at in new ways. The more you look the more you see. Very Happy
View user's profile Send private message Send e-mail Visit poster's website Widgets
Lawrence



Joined: 31 May 2006
Posts: 8
Location: australia

Posted: Thu Jul 13, 2006 - 9:14 am    Post subject: Key90 4x4 integrity Reply with quote

purvisa wrote:
With a 4x4 grid, the math gets a little more interesting.


purvisa wrote:
Writing a program to generate random Key 90 puzzles should not be too difficult. Indeed, it may well take only a day or two, once one is coded up, to calculate all possible general forms (in which letters are not assigned numerical value, but the possible grids are all computed, which is far smaller than the total number of puzzles. From there, all possible letter changes (switching A for B to create a different appearance for an identical pattern) and all possible number assignment combinations could be computed, the totals worked out, and a huge supply of puzzles prepared. The variation, then, of starting data and the evaluation of relative difficulty should be all that remains when setting them up.


Can you tell me why moving a row or column changes the difficulty of the puzzle? This seems to be the only change to the integrity of the puzzle. I am glad it is so.
If it is a hard puzzle the chances are better than 50 - 50 that it will change into another hard puzzle.

Then there is the sorting of the puzzles to make sure that there are no duplicates Geek Sorting, sorting, sorting. Very Happy Very Happy
View user's profile Send private message Send e-mail Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group