Hello,

In the following code below i have 1 method that fills a array with 11 random value's.(wich works as intended).

My question is how do i take each generated random value created in the array, and perform a calculation with each of those values? (preffered in a new method).

``````const byte AantalElem = 11;
int[] ArrayElem = new int[AantalElem];``````
``````public void FillArrayRandom(int[] ArrayElem)
{
Random RndInt = new Random();

for (int i = 0; i < ArrayElem.Length; i++)
{
ArrayElem[i] = RndInt.Next(0, 9999);
}
}/*FillArrayRandom*/``````

And is it possible to "call" upon those calculated value's in a new array aswell?

``ArrayElem[i] = (21 * ArrayElem[i]) / MaxHoogte;``

But i have no idea how to insert this, if i do my random generated numbers are between 0 and 10. (not even sure the line above is even correct).

Any help appreciated.
Regards.

Edited by Nerathas: n/a

2
Contributors
3
Replies
7
Views
7 Years
Discussion Span
Last Post by ddanbe

The line ArrayElem = (21 * ArrayElem) / MaxHoogte; is correct.
If MaxHoogte is een integer you have to take into account you are doing an integer division.
Don't know why you use 0,9999 if you want to generate random integers between 0 and 10.

The line ArrayElem = (21 * ArrayElem) / MaxHoogte; is correct.
If MaxHoogte is een integer you have to take into account you are doing an integer division.
Don't know why you use 0,9999 if you want to generate random integers between 0 and 10.

Hello,

The random generated numbers are between 0 and 9999 :).
If i want to do some calculations with a certain value do i have to call it with a index?

With jagged/2dim array i could use [.. , ..], can i do something similar with a 1-dim table like mentioned in my op?

``````for (int i = 0; i < ArrayElem.Length; i++)
{                ArrayElem[5] = //......??
}``````

Regards.

Edited by Nerathas: n/a

Yeah, why not?
But on line 2 of your last code change ArrayElem[5] into ArrayElem[[B]i[/B]]