Computing.Net > Forums > Programming > LOTTO generator; RFC

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

LOTTO generator; RFC

Reply to Message Icon

Name: Mechanix2Go
Date: December 9, 2007 at 02:38:03 Pacific
OS: w2k sp3
CPU/Ram: PIII 933/256MB
Product: brand x
Comment:

Please giive this a look and let me know if it makes sense. It seems 'random enough' ; only 3 duplicates in a run of 10,000+

::== gen6.bat

:: generate set[s] of 6 lotto numbers in the range 01 to 49

@echo off
setLocal EnableDelayedExpansion

if %1'==' goto :main

:gen requested number of sets
for /L %%n in (1 1 %1) do (
call :main
)
goto :eof

:main
@echo off > 6
for /L %%a in (1 1 6) do (
call :sub1
)
sort < 6 > 6sorted

for /f "tokens=* delims= " %%a in (6sorted) do (
set S=!S!%%a
)

echo !S! >> picklist
set S=
del 6*

goto :eof

:sub1
:loop
set N=!random:~-2!
if !N! equ 0 goto :loop
if !N! gtr 49 goto :loop
find "!N!" < 6 > nul
if not errorlevel 1 goto :loop
echo !N! >> 6
goto :eof



=====================================
If at first you don't succeed, you're about average.

M2




Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: December 9, 2007 at 06:37:57 Pacific
Reply:

Hi M2,


set N=!random:~-2!
if !N! equ 0 goto :loop
if !N! gtr 49 goto :loop

The above three lines can be replaced by the following one line:

set /a N = !random! % 49 + 1

Which sets N to be a random number between 1 and 49. The % character is the modulo operator. Also this produces consistent results whereas your version sometimes produces 1, 2, 3 and sometimes 01, 02, 03.

Next challenge: make it work without producing a temporary file! Anyone up for the challenge?

Finally, I remember reading that such Lotto number generators shouldn't be used, because computer-based pseudo-random-number generators are not random enough, and if you are lucky enough to win the jackpot the chances are that many others, out of the millions who enter, will also have used the same random number generator (even though they will have used a different program, the random number generator algorithm may have been the same.) Therefore, you will have to share your £14million with many others; whereas, if you simply used a die or something really random, the chances are that you will take all the winnings yourself.

Cheers,
Klint

PS Good luck, and will you buy me a beer when you win!!!


0

Response Number 2
Name: Deimos
Date: December 9, 2007 at 09:28:18 Pacific
Reply:

Can you tell me what programing language is that???

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


0

Response Number 3
Name: klint
Date: December 9, 2007 at 11:53:05 Pacific
Reply:

It's Win32 Command Processor (batch file) language!


0

Response Number 4
Name: Deimos
Date: December 9, 2007 at 13:31:43 Pacific
Reply:

Ok thanks.

And i tought c++ was hard!! XD

AMD ATHLON X2 5200 2.6ghz;
ASUS M2N-E SLI;
2GB DDR800 KINGSTON;
ASUS GF8600GTS;
Seagate 7200rpm 320GB;


0

Response Number 5
Name: klint
Date: December 9, 2007 at 14:48:35 Pacific
Reply:

C++ is a practical language. Batch file language is not for use as a general-purpose programming language, except for masochists.

If I were to write a Lotto application like that, I'd probably do it in Java, as an applet that can run inside a web browser. But doing it "batch language" demonstrates that this language is more powerful than many people realise, although it is quirky.


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: December 9, 2007 at 20:02:50 Pacific
Reply:

I ran this script though 10,000 iterations on 2K, then XP, then Vista for a grand total of 30,000 loops. (Aside: Took between 5 and 10 minutes on Vista. 2K took hours. XP is unknown; I started it before I went to sleep. In all three cases, the script spent most of its time in find.exe. This is irrelevant, though, because only XP and Vista share the same hardware.)

Out of those iterations, the number of repeats were:
2K: 3 / 10000 (0.03%)
XP: 4 / 10000 (0.04%)
Vista: 2 / 10000 (0.02%)
Combined: 32 / 30000 (0.106666666666667%)


0

Response Number 7
Name: Mechanix2Go
Date: December 10, 2007 at 04:43:01 Pacific
Reply:

Hi Klint,

"Batch file language is not for use as a general-purpose programming language, except for masochists."

Guilty as charged.

Thanks for the feedback. I'll addfress the hardest bit first.

Without getting into astrology, poltics or religion, even if many people use the exact same program it seems unlikely in the extreme that many will generate the same number.

Good idea about using mod 49. One reason for my 2 place approach is to enable the SORT. As I'm sure you know, without leading zeros 2 gets put after 10. LOL

If I forgo the SORT I can probably lose the temp files. Not obvious how to check for dups without sorting.

Iif I win the jackpot I'll buy all you guys a beer and a siixpak of dragonladies. ;)

Razor2.3,

10000 took 27 minutes on 2K PIII 933/256MB.



=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Alpha Blending (Fading) javascript hangman game h...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: LOTTO generator; RFC

RFC reading utility www.computing.net/answers/programming/rfc-reading-utility/3234.html

Sine wave generation using Java www.computing.net/answers/programming/sine-wave-generation-using-java/12012.html

Generator Application www.computing.net/answers/programming/generator-application/9806.html