I need help in making a function that randomly chooses between two numbers that I give through the parameters. Please give me a hint or something. Thanks in advance guys.

so far nothing except googling the function generating random numbers from a defined area. e.g. any number from 1 to 30. Haven't found anything significant yet.

i'm trying to make it choose only one of the two given numbers. In particular i want it to chose either 1 or -1. I want to repeat the process for 2 and -2

So have your routine choose either 0 or 1 (so use rand() % 2) and then select the appropriate number with an if statement. I'm sure there are plenty of other (and better) ways to do it but that's off the top of my head.

So have your routine choose either 0 or 1 (so use rand() % 2) and then select the appropriate number with an if statement. I'm sure there are plenty of other (and better) ways to do it but that's off the top of my head.

I tried it your way but the results are the same every time. What I'm looking for is a function that chooses either 1 or -1 and then either 2 or -2 and that's it

>So have your routine choose either 0 or 1 (so use rand() % 2)
>and then select the appropriate number with an if statement.rand() % 2 is especially risky when it comes to getting the same result every time (for reasons I'm not interested in detailing at the moment). This has worked better for me in the past:

if (rand() < RAND_MAX / 2)
{
/* Pick one number */
}
else
{
/* Pick the other number */
}

if you want to get ranom number between 1 and 2 you can not do this

num = rand() % 2

you must instead do this

num = rand() % 2 + 1

because otherwise will never get the number 2 and will lots of times get 0.

The OP doesn't want a random number between 1 and 2, he wants to randomly choose between two options. It doesn't matter what two random numbers you use for the comparison, or even if you compare against a range. The only thing that matters is that there are ultimately two randomized results.

Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}

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 ...