int choices[2] = {2,3}; //choose between 2 and 3
// Seed the random generator with srand()
// Use rand() to pick either 0 or 1 and store in variable x
int L = choices[x];

Google for srand() and rand() to find out how they work, or read this

thx niek_e, but is there any other way how i to make this with a single line without to use much variables ? Idea is to pick one of these two chars A or B.

thx niek_e, but is there any other way how i to make this with a single line without to use much variables ? Idea is to pick one of these two chars A or B.

Like

char L = random(from char A, or char B);

u can use the function that i gave as

char x = random('A', 'B');

just change its prototype to

char random(char a, char b);

i hope thats simple enough. i guess thats simplest way to do it.

hi there i'm new to this and I have a problem with dreamweaver and don't know who to ask.
when I try to view my pages with hitting F12 it keeps saying that I have a broken link and a DNS error.
can you point me in the right direction?
Thank you in advance
Robert

hi there i'm new to this and I have a problem with dreamweaver and don't know who to ask.
when I try to view my pages with hitting F12 it keeps saying that I have a broken link and a DNS error.
can you point me in the right direction?
Thank you in advance
Robert

char AorB(char A, char B) { char T = rand%2 ? A : B ; return T; }

rand()%2 might not be very random. Historically rand() has been written with very non-random low order bits, and using modulus to fit the range uses the low order bits. rand()%2 only uses one bit, so you might end up with a predictable pattern like 1,0,1,01,0,1,0... A better way to pick between two options is to divide RAND_MAX by 2 and look for values in that range:

template <typename T>
T RandomChoice(T a, T b)
{
return (rand() < RAND_MAX / 2) ? a : b;
}

p.s. I am not picking on you firstPerson. Other examples in this thread used the same thing, so my post applies to them too.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :