Re: Seeding Randomization on CMD (WinXP Pro)

From: Phil Robyn [MVP] (zipprobyn_at_berkeley.edu)
Date: 10/06/04


Date: Wed, 06 Oct 2004 00:35:27 -0700

PsyB wrote:

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

-- 
Phil Robyn
Univ. of California, Berkeley
u n z i p   m y   a d d r e s s   t o   s e n d   e - m a i l


Relevant Pages

  • Re: Very Simple script driving me nuts!
    ... >> of shell programming it seems thats biting me in the arse, ... >> to write an utterly simple script to save me some time. ... >> 5 echo ... echo -n "CMD: $*" ...
    (comp.unix.shell)
  • Re: Very Simple script driving me nuts!
    ... > from shell scripting over the years, for the most part been working ... > 5 echo ... > $* so I don't have type any surrounding quotes when I use my script, ... echo -n "CMD: $*" ...
    (comp.unix.shell)
  • Re: How can I kill a stuck cmd.exe remotely?
    ... sample script code... ... Microsoft MVP - Windows Server Management Infrastructure ... > the cmd would stuck for some reasons I did not know. ... > something in order to run the WMI thing? ...
    (microsoft.public.windowsxp.wmi)
  • Re: Seeding Randomization on CMD (WinXP Pro)
    ... However since my script takes exactly the ... > change the execution time so that the number pulled from the pool ... > real random number on CMD? ... Returns an exit code of a pseudo-random number based on ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: CD to acc
    ... I m learning python, so thought i should write small py script to ... os.system (cmd) ... Run this script, while you are in the mounted CD ROM dir... ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)