Quote:
Originally Posted by colin9876
nasty stuff C language by the looks of it!
|
Not all. It's beautifully elegant, very safe to code but just not what you are used to. BTW you keep typing C - this may be shorthand on your part but this is C# - which is different to C in many ways
Quote:
|
whats the rnd function in C?
|
As this is C# not C there are no standard functions/libraries - it relies upon the .NET Framework.
Quote:
I see .Net framework has
double RandomNumber = RandomClass.NextDouble();
|
That's the one (or one of several)
More completely and with correct syntax. You need a new Random object to create the numbers and the C# compiler will complain that it can't convert a double to an int (because doubles are larger than ints so information can be lost) so you will need to cast it to an int yourself
Code:
Random rand = new Random();
public int timer(int[]x, int[]y, int n, double spread)
{
...
x[i]=x[i]+(int)((2*rand.NextDouble()-1)*spread);
...
}
Here I've done it for you, with source. I haven't time to test it as I have lost the B4PPC test prog I used but as it got through the compiler it is probably OK.