[.bat] Generer nombre aléatoir entre 2 bornes

StuxNET -  
dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

Je m'ennuis en cours et la seule occupation me motivant est de réaliser des programmes (pourris) en batch.
Je souhaite réaliser un vulgaire "+ou-" (du moins en réaliser plusieurs, differents), mais il me manque une commmande batch importante : comment generer un nombre aléatoir compris entre 2 bornes?

Merci, bonne journée
C.C

2 réponses

  1. lecarpla
     
    Salur StuxNet,

    As tu été voir ici?

    http://www.commentcamarche.net/forum/affich-3131280-batch-un-random-definit
    1
  2. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    hello
    C:> set HI=200 
    C:> set LO=100 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    185 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    124 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    171 
    C:> 
    C:> set HI=600 
    C:> set LO=300 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    345 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    433 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    508 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    459 
    C:> set /a x=(%RANDOM%%(%HI%-%LO%+1))+%LO% 
    444 
    C:>
    1