Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use random in BATCH script?

How to use random in BATCH script?

like image 829
IAdapter Avatar asked Apr 25 '11 10:04

IAdapter


People also ask

What does %% mean in batch script?

Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> )

How do I generate a random number in bash?

The random number or a range of random numbers can be generated using the $RANDOM variable. It generates a random number between 0 and 32767 by default. But you can set the range of numbers for generating random numbers by dividing the value of $RANDOM with a specific value.

How do you use random in CS?

To generate random numbers in C#, use the Next(minValue, MaxValue) method. The parameters are used to set the minimum and maximum values. Next(100,200); We have set the above method under Random() object.


2 Answers

%RANDOM% gives you a random number between 0 and 32767.

Using an expression like SET /A test=%RANDOM% * 100 / 32768 + 1, you can change the range to anything you like (here the range is [1…100] instead of [0…32767]).

like image 128
mousio Avatar answered Nov 14 '22 04:11

mousio


%RANDOM% gives you a random number between 0 and 32767.

You can control the number's range with:

set /a num=%random% %%100 

- will produce number between 0~99.

This one:

set /a num=%random% %%100 +1 

- will produce number between 1~100.

like image 40
GaryNg Avatar answered Nov 14 '22 03:11

GaryNg