this is my first post:) Alright I'm trying to create a program that randomly either adds 1 or -1 to the start value of 0. This process proceeds in 500 steps or so and then the end result needs to be added to an array. This is how far I've reached:
using System;
using System.Collections.Generic;
namespace dimensionrandomwalk
{
class MainClass
{
public static void Main (string[] args)
{
Random rnd = new Random();
int[] x;
x = new int[500];
for (int i = 0; i < 500; i++){
int L = rnd.Next (0, 2);
int L1 = -1;
int L2 = 1;
if (L == 0) {
x [i] = L1;
} else if (L == 1) {
x [i] = L2;
}
x[i] = x[i+1]+x[i];
Console.WriteLine (x[i]);
}
}
}
}
I'm going to make two arrays, one that contains the 500 steps and one with 100 end results. but I can't get it to add x[1] with x[2] and so on untill x[500]. Thank you:)