Not Yet Answered # Random Number Generator

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

0

I am required to generate "n" random numbers of which each random number ranges from -10,000,000 to 10,000,000. I tried using rand() and changing the range, but it only has a max range of 32,000 or so. What is a good function or algorithm that I could use to achieve this and what library would I have to include in my code?

*Edited 6 Years Ago by .:Pudge:.*: n/a

0

Well first of if you need random numbers to actually compute something else, don't use rand() for anything, it simple isn't random enough. [Basically, rand() has very poor lower bits.] e.g. see http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx

So that leads us to looking for a good [enough] random number generator. The current defacto standard for most scientific simulations is currently MesenneTwister [e.g. GEANT, gsl, octave]. Mersene-Twister can be found at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html. Note, this site links to the original Mersenne Twister, and some of the faster (but same randomness) implementations that exist. All of the links go to open source code. It also links to the scientific papers about the random number generator, be warned **heavy** maths.

Finally, what you are after is to create a random number between to numbers (considered a range). Using your favorite random number generator, you are typically going to get a random number between 0 and 1. If you are using Mersenne Twister you have a choice of getting the number fully inclusive, partly inclusive and totally exclusive [i.e. you can/cannot get the extreme values one and zero].

You have to be careful about that choice and its effect on your applications, then you want to convert it into your range. This is done like this:

`double rV= lowerNumber+ (higherNumber-lowerNumber)*random();`

Note that you might have to cast the number to an integer, again be careful to ensure that you can/can't get the lowest/highest numbers in the range.

*Edited 6 Years Ago by StuXYZ*: n/a

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

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);
}
```

the function that I created to find the ...