# RandomNumber

How Do You Do A Random Number Out Of Your Own Selection Of Numbers, For Example You Have 1, 2, 3 and u want the computer to choose one of the 3 at random.

X:=Random(3)+1; { returns random number between 1..3}

...or maybe you want to print a random string ?

var s:array[1..3] of string;

begin

s[1]:='string1';

s[2]:='abc';

s[3]:='xyz';

X:=Random(3)+1;

writeln(s[x]);

...or maybe you want to print a random value ?

var s:array[1..3] of integer;

begin

s[1]:=-50;

s[2]:=1000;

s[3]:=666;

X:=Random(3)+1;

writeln(s[x]);

Does this help ?

Re Lance

: How Do You Do A Random Number Out Of Your Own Selection Of Numbers, For Example You Have 1, 2, 3 and u want the computer to choose one of the 3 at random.

:

• Make sure you put the "randomize" procedure in before getting the number.

: X:=Random(3)+1; { returns random number between 1..3}

:

: ...or maybe you want to print a random string ?

: var s:array[1..3] of string;

: begin

: s[1]:='string1';

: s[2]:='abc';

: s[3]:='xyz';

: X:=Random(3)+1;

: writeln(s[x]);

:

: ...or maybe you want to print a random value ?

: var s:array[1..3] of integer;

: begin

: s[1]:=-50;

: s[2]:=1000;

: s[3]:=666;

: X:=Random(3)+1;

: writeln(s[x]);

:

: Does this help ?

: Re Lance

:

: : How Do You Do A Random Number Out Of Your Own Selection Of Numbers, For Example You Have 1, 2, 3 and u want the computer to choose one of the 3 at random.

: :

:

:

:

• :

: Make sure you put the "randomize" procedure in before getting the number.

what is the randomize procedure?

• The randomize procedure gets the current tick of your computer's internal timer (or something like that) and then sets it as a variable so when you call random(), the program has some sort of a number to put through several formulas.

Well anyway, it is because there is really no such thing as just "random" (ie. there is always some factor of why a particular number has been chosen).

• Radomize simply takes the already chose number and throws it back into the hat... if u dont use randomize the random number will stay they same until u restart the program... so u can use it both ways depending on ur preference.