Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: Mechanix2Go
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 EnableDelayedExpansionif %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 > 6sortedfor /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

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,
KlintPS Good luck, and will you buy me a beer when you win!!!

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;

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;

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.

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%)

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

![]() |
Alpha Blending (Fading)
|
javascript hangman game h...
|

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