(DM42) Lottery number generator programming
|
02-11-2019, 07:35 PM
(This post was last modified: 02-11-2019 07:45 PM by Dieter.)
Post: #2
|
|||
|
|||
RE: (DM42) Lottery number generator programming
(02-10-2019 09:54 AM)psw Wrote: I am a sheer beginner of DM42 programming and interesting in a simple and useful program. I see this is your first post here, so welcome to the forum. Regarding the intended program, I think we have to start from scratch here. There seem to be several misconceptions about various DM-42 (or Free42, or HP-42s) commands. For instance it is not a good idea at all to seed the random number generator before every single RAN call. Essentially you can forget about SEED unless you want to reproduce a certain random number sequence. Also your code would not generate integers between 1 and 18 but between 0 and 17 – you have to add 1 here. Then there are loop counters DSE and ISG so that manually decrementing R00 and checking whether it is > 0 or not is not required. This works like a FOR-loop in other programming languages. Finally ASTO does not store a value into Alpha, but it stores the first six characters of Alpha into the specified register (that's why the command then reads ASTO 03 or ASTO ST X or whatever). So the code snippets you posted will not work, neither separately nor combined. OK, let's forget about all this. The program you want would have to behave like this: Code: Generate X random integers between 1 and Y The following Free42 program implements this algorithm. The max. random integer Y is stored in "MAX", flag 01 is used to mark the first loop, it is automatically cleared when tested, and the loops are controlled by ISG and DSE. The loop counter is in R00, the test loop counter is on the stack. The random integers are stored in R01, R02, R03 etc. If, say, the 4th number has been calculated, the program compares this to R03, R02 and R01 to see whether there are duplicates. If there are, a new number is calculated. If not, the new R is stored in the respective register, here R04. The first two lines correct input errors ("18 different numbers out of 4" instead of vice versa) and the final lines restore the original Y and X and remove "MAX" (cleanup). This way you can repeat the whole thing by simply pressing [R/S]. This program can be optimized. For instance the whole flag thing can be removed. ;-) But it is more clear this way. Now take a look at the program and ask everything you don't understand. Code: 00 { 90-Byte Prgm } Note: "Rv" means R↓ and line 34 appends a space to Alpha. The following example was obtained after 0,12345 [SEED] on Free42. But I can't say if this will produce the same numbers on the DM-42. 18 [ENTER] 4 XEQ"RANDOM" 4 7 3 16 [R/S] 9 6 17 4 [R/S] 3 16 4 18 etc. Now, what about adding a sorted output ?-) Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(DM42) Lottery number generator programming - psw - 02-10-2019, 09:54 AM
RE: (DM42) Lottery number generator programming - Dieter - 02-11-2019 07:35 PM
RE: (DM42) Lottery number generator programming - Thomas Klemm - 02-12-2019, 12:57 AM
RE: (DM42) Lottery number generator programming - psw - 02-12-2019, 05:56 AM
|
User(s) browsing this thread: 1 Guest(s)