PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > %random%
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
%random%

Réponse
 
LinkBack Outils de la discussion
Vieux 10/10/2007, 14h30   #1
bvb47 via WinServerKB.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut %random%

Hello!,

I'm trying to obtain a random number in batch file.

if I type
> set /a X=%random%%108

in command prompt work ok, but if I put this instruction in batch file, don't
work!

anybody know why?

thanks!

--
Message posted via http://www.winserverkb.com

  Réponse avec citation
Vieux 10/10/2007, 18h22   #2
McKirahan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: %random%

"bvb47 via WinServerKB.com" <u37442@uwe> wrote in message
news:797b38778d19c@uwe...
> Hello!,
>
> I'm trying to obtain a random number in batch file.
>
> if I type
> > set /a X=%random%%108

> in command prompt work ok, but if I put this instruction in batch file,

don't
> work!
>
> anybody know why?


Try doubling the use of %:

http://www.aumha.org/a/batches.php

"NOTE: The %% is necessary because this is in
a batch file which, otherwise, would give a special
meaning to a single %. "


  Réponse avec citation
Vieux 10/10/2007, 18h24   #3
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: %random%


"bvb47 via WinServerKB.com" <u37442@uwe> wrote in message
news:797b38778d19c@uwe...
> Hello!,
>
> I'm trying to obtain a random number in batch file.
>
> if I type
>> set /a X=%random%%108

> in command prompt work ok, but if I put this instruction in batch file,
> don't
> work!
>
> anybody know why?
>
> thanks!
>
> --
> Message posted via http://www.winserverkb.com
>


At a command prompt I get:

nnnnn%108

where nnnnn is a random integer. In a batch file I get:

nnnnnn08

This is because %1 is blank. If I pass "Test" to the batch file as the first
argument, I get an error because "Test" is not numeric. If I pass 23 as the
argument, I get:

nnnnnn2308

Seems to work for me. Of course the environment variable only lasts until I
exit the command prompt.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


  Réponse avec citation
Vieux 10/10/2007, 19h07   #4
bvb47 via WinServerKB.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: %random%

the solution is written by BSOD in nabble forum:
----------------
BSOD wrote:
Cos in a batch %108 is interpreted as a command line parameter passed to the .
bat, the same as %0 and %1 etc etc.

use this :

SET /A X=%RANDOM%%%108%
---------------

thanks to all!.

bvb47 wrote:
>Hello!,
>
>I'm trying to obtain a random number in batch file.
>
>if I type
>> set /a X=%random%%108

>in command prompt work ok, but if I put this instruction in batch file, don't
>work!
>
>anybody know why?
>
>thanks!


--
Message posted via http://www.winserverkb.com

  Réponse avec citation
Vieux 10/10/2007, 19h08   #5
bvb47 via WinServerKB.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: %random%

the solution is written by BSOD in nabble forum:
----------------
BSOD wrote:
Cos in a batch %108 is interpreted as a command line parameter passed to the .
bat, the same as %0 and %1 etc etc.

use this :

SET /A X=%RANDOM%%%108%
---------------

thanks to all!.

bvb47 wrote:
>Hello!,
>
>I'm trying to obtain a random number in batch file.
>
>if I type
>> set /a X=%random%%108

>in command prompt work ok, but if I put this instruction in batch file, don't
>work!
>
>anybody know why?
>
>thanks!


--
Message posted via http://www.winserverkb.com

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h48.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10254 seconds with 13 queries