SRL Archive - C/C++ Help and Tutorials

Choosing random element from array


Repentinus

2007-12-23 18:55:32

'Ello. I have array:
long double Array[61] = {
1,
2,
3,
4,
5,
6,
7,
8,
9,
0,
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o,
p,
q,
r,
s,
t,
u,
v,
w,
x,
y,
z,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z
};

And I need to choose random element from it. And it must be different every time I run the program or if I repeat action. Can someone help?

BenLand100

2007-12-23 19:40:58

You'll need Time.h and StdLib.h

srand((unsigned)time(0)); //randomized the random number generator
long double val = Array[rand()%61]; //val is a random value from your array.

Repentinus

2007-12-24 07:34:39

TY, Now my program works correctly, but I want edit it so, that I can copy text from my CMD prog.

R0b0t1

2007-12-24 14:57:46

You need to click on the icon of the command window and there should be a "options" thingy.

Repentinus

2007-12-24 17:15:26

Well, thank you for that great advice, but how I can directly write to my program: Mark x, Copy x .

R0b0t1

2007-12-24 18:11:48

Oooh…

I think its possible to read/write to the system clipboard, as SCAR does when you select a color, but I have no clue how to do that.