Seeding Randomization on CMD (WinXP Pro)

P

PsyB

Can anyone tell me how to get a *PROPER* random number? I have defined a
variable as follows:

set randnumber=%random%

When querying the contents of my variable %randnumber% when staying
inside the CMD prompt without an exit, the variable, of course, is
randomized. However since my script takes exactly the same amount of
time to run each time it is run, the random number will always be the
same since the %random% variable is never seeded properly (indeed it
follows the same progression of "random" numbers each and every time
that CMD is started). I have tried various way to cause inconsistency in
how fast the script is executed including netstat, ping and dir -
anything that might change the execution time so that the number pulled
from the pool is different, though no matter what I have tried I end up
centering around a single number. Is there any way to generate a real
random number on CMD? Or is there any way to seed the CMD line with the
time or some other variable that would allow a better randomization? Use
of pause is out of the question, though, as this needs to be a
transparent script.


--
-=[PsyB]=-

Greater in battle than the man who would conquer a thousand-thousand men
is he who would conquer just one - *himself*.

--Dhammapada--
 
P

PsyB

It is providing a Random-esque number, however if I put this into a BAT
file and execute it repeatedly then I will only get a difference of
maybe 10 or so.

set evnum=%random%
echo %evnum% >test.txt

Ideally what I am trying to accomplish it to have the number completely
random so that when it is run it repeatedly I will get results such as:

16452
100
5000
3828
32000
etc.

instead of what I am getting now:

15819
15855
15879
etc.

PsyB
 
M

Mark V

In said:
Can anyone tell me how to get a *PROPER* random number? I have
defined a variable as follows:

set randnumber=%random%

When querying the contents of my variable %randnumber% when
staying inside the CMD prompt without an exit, the variable, of
course, is randomized. However since my script takes exactly the
same amount of time to run each time it is run, the random number
will always be the same since the %random% variable is never
seeded properly (indeed it follows the same progression of
"random" numbers each and every time that CMD is started). I have
tried various way to cause inconsistency in how fast the script is
executed including netstat, ping and dir - anything that might
change the execution time so that the number pulled from the pool
is different, though no matter what I have tried I end up
centering around a single number. Is there any way to generate a
real random number on CMD? Or is there any way to seed the CMD
line with the time or some other variable that would allow a
better randomization? Use of pause is out of the question, though,
as this needs to be a transparent script.

All I can offer is this:
http://www.optimumx.com/
=================
Random Number Generator v1.00 (Random.exe) Last Updated:
09/03/1998

Returns an exit code (Errorlevel) of a pseudo-random number based on
lowerbound and upperbound numbers passed as arguments. The number
returned is much more random than the %RANDOM% variable. Use
'Random.exe /?' to view the syntax."
=================

I have used it for years but can only say that it is *more* random
than %random%. I have no statistical study for the tool.
 
P

Phil Robyn [MVP]

PsyB said:
Can anyone tell me how to get a *PROPER* random number? I have defined a
variable as follows:

set randnumber=%random%

When querying the contents of my variable %randnumber% when staying
inside the CMD prompt without an exit, the variable, of course, is
randomized. However since my script takes exactly the same amount of
time to run each time it is run, the random number will always be the
same since the %random% variable is never seeded properly (indeed it
follows the same progression of "random" numbers each and every time
that CMD is started). I have tried various way to cause inconsistency in
how fast the script is executed including netstat, ping and dir -
anything that might change the execution time so that the number pulled
from the pool is different, though no matter what I have tried I end up
centering around a single number. Is there any way to generate a real
random number on CMD? Or is there any way to seed the CMD line with the
time or some other variable that would allow a better randomization? Use
of pause is out of the question, though, as this needs to be a
transparent script.
- - - - - - - - - - begin screen capture - - - - - - - - - -
<Win2000> c:\cmd>for /l %a in (1,1,40) do @demo\RandomNumber
28706274
17320870
68372699
98623175
89578187
1836712
70704052
38107119
1034443
96581319
80050619
83072647
47275739
91770784
32657180
82783096
75807084
35338392
74495116
64171344
44289868
87174368
72058173
31741854
89680318
27638726
61450241
16231441
48446964
17055075
8100615
17027914
86868443
2760513
66488600
26492228
96420249
62050581
8049294
77723888

<Win2000> c:\cmd>rlist demo\RandomNumber.cmd
=====begin c:\cmd\demo\RandomNumber.cmd ====================
1. @echo off
2. set S1=%time::=%
3. set S1=%S1: 0=%
4. set S1=%S1:.=-%
5. set S1=%S1:-0=-%
6. set /a my_random_number = "%random% * %S1%"
7. echo %my_random_number%
=====end c:\cmd\demo\RandomNumber.cmd ====================
- - - - - - - - - - end screen capture - - - - - - - - - -
 
P

PsyB

Mark said:
In microsoft.public.win2000.cmdprompt.admin PsyB wrote:




All I can offer is this:
http://www.optimumx.com/
=================
Random Number Generator v1.00 (Random.exe) Last Updated:
09/03/1998

Returns an exit code (Errorlevel) of a pseudo-random number based on
lowerbound and upperbound numbers passed as arguments. The number
returned is much more random than the %RANDOM% variable. Use
'Random.exe /?' to view the syntax."
=================

I have used it for years but can only say that it is *more* random
than %random%. I have no statistical study for the tool.
Thanks Mark! The results are much better than the cmd random!
(0-65535)
10/06/04 14:36:47.98 40675
10/06/04 14:36:48.21 8629
10/06/04 14:36:48.56 21153
10/06/04 14:36:48.94 49863
10/06/04 14:36:49.30 5391
10/06/04 14:36:49.69 46269
10/06/04 14:36:50.03 43875
10/06/04 14:36:50.37 39443
10/06/04 14:36:50.71 46841
10/06/04 14:36:51.10 24825
10/06/04 14:36:51.48 56105
10/06/04 14:36:51.84 56887
10/06/04 14:36:52.23 29617
10/06/04 14:36:52.63 33519
10/06/04 14:36:53.06 31879
10/06/04 14:36:53.45 42001
10/06/04 14:36:53.83 12659
10/06/04 14:36:54.22 60385
10/06/04 14:36:54.58 42743
10/06/04 14:36:54.97 49665
10/06/04 14:36:55.36 6645
10/06/04 14:36:55.77 62843
10/06/04 14:36:56.15 59877
10/06/04 14:36:56.59 55317
--
-=[PsyB]=-

Greater in battle than the man who would conquer a thousand-thousand men
is he who would conquer just one - *himself*.

--Dhammapada--
 
P

PsyB

Phil said:
- - - - - - - - - - begin screen capture - - - - - - - - - -
<Win2000> c:\cmd>for /l %a in (1,1,40) do @demo\RandomNumber
28706274
17320870
68372699
98623175
89578187
1836712
70704052
38107119
1034443
96581319
80050619
83072647
47275739
91770784
32657180
82783096
75807084
35338392
74495116
64171344
44289868
87174368
72058173
31741854
89680318
27638726
61450241
16231441
48446964
17055075
8100615
17027914
86868443
2760513
66488600
26492228
96420249
62050581
8049294
77723888

<Win2000> c:\cmd>rlist demo\RandomNumber.cmd
=====begin c:\cmd\demo\RandomNumber.cmd ====================
1. @echo off
2. set S1=%time::=%
3. set S1=%S1: 0=%
4. set S1=%S1:.=-%
5. set S1=%S1:-0=-%
6. set /a my_random_number = "%random% * %S1%"
7. echo %my_random_number%
=====end c:\cmd\demo\RandomNumber.cmd ====================
- - - - - - - - - - end screen capture - - - - - - - - - -
Thank you!

I had tried something similar, but this produces results similar to CMD
random for me though. This is because I have to run the randomization
from a fresh CMD window each time and need a higher differential between
the results I attained. I get this when issuing RandomNumber.cmd with
an echo %date% %time% %my_random_number% >>Random.log at the end, each
execution in a fresh CMD state (IE:DC the CMD file). When finished the
randomization will need to be run 6 times per second, so I need a higher
degree of randomization. I appreciate your time though!

10/06/04 14:46:18.54 -127076587
10/06/04 14:46:18.76 -127076612
10/06/04 14:46:19.10 -126613869
10/06/04 14:46:19.44 -126613903
10/06/04 14:46:19.83 -126613942
10/06/04 14:46:20.30 -126006586
10/06/04 14:46:20.65 -126006621
10/06/04 14:46:21.03 -125543869
10/06/04 14:46:21.42 -125543908
10/06/04 14:46:21.78 -125543944
10/06/04 14:46:22.14 -125081184
10/06/04 14:46:22.53 -125081223

--
-=[PsyB]=-

Greater in battle than the man who would conquer a thousand-thousand men
is he who would conquer just one - *himself*.

--Dhammapada--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top