random walk 3D [no boundary + clusters]

Random Walk 1.5
Inspired by “The Nature of Code” by Daniel Shiffman and it’s python translator Jake Hebbert.
Using C# in Grasshopper for Rhinoceros

//	Philipp Siedler
//	Daniel Shiffman "The Nature of Code"
//	Random Walk 1.5
private void RunScript(int seed, int time, ref object A, ref object B, ref object C, ref object D, ref object E, ref object F)
{
    List <Point3d> pList = new List<Point3d>();
    List <Point3d> pListEx = new List<Point3d>();

    List <int> xList = new List<int>();
    List <int> indexList = new List<int>();

    Walker w = new Walker();
    Random random = new Random(seed);

    int counter = 0;
    indexList.Add(counter);

    for(int i = 0; i < time; i++){
      int rnd = random.Next(0, 6);
      w.step(rnd);

      if(w.boundRebounceCount < 100){
        pListEx.Add(w.pos());
      }
      else{
        pList.Add(w.pos());
      }
      counter++;


      if(indexList.Count() == 1){
        indexList[0] = counter;
      }

      if(w.x == 0 && w.y == 0 && w.z == 1){
        indexList.Add(counter);
        counter = 0;
      }
    }



    A = pList;
    B = xList;
    C = counter;
    D = indexList;
    E = pListEx;
    F = w.growthCounter;

  }

  // <Custom additional code> 
  public class Walker
  {
    public double x;
    public double y;
    public double z;
    public int rnd;
    public int boundRebounceCount;
    public int explosionNum;
    public int growthCounter;

    //Constructor that takes arguments.
    public Walker(){
      x = 1.0;
      y = 1.0;
      z = 1.0;
      rnd = 0;
      growthCounter = 0;
      boundRebounceCount = 100;

    }

    public Point3d pos(){
      Point3d posPt = new Point3d(x, y, z);
      return posPt;
    }

    public int step(int rnd){

      int choice = rnd;
      int explosionNum = 0;


      //GROWING UP
      if(boundRebounceCount == 100 && growthCounter < 750){
        if (choice <= 0){
          x++;
          growthCounter++;
        }
        else if(choice <= 1){
          x--;
          growthCounter++;
        }
        else if(choice <= 2){
          y++;
          growthCounter++;
        }
        else if(choice <= 3){
          y--;
          growthCounter++;
        }
        else if(z > 5 && choice <= 4){
          z--;
          growthCounter++;
        }
        else if(choice <= 5){
          z++;
          growthCounter++;
        }
      }

      if (growthCounter == 750){
        boundRebounceCount = explosionNum;
        growthCounter = 0;
      }
      else if (z <= 0){
        boundRebounceCount = explosionNum;
      }

      //EXPLODING
      double factor = 1;

      if(boundRebounceCount == 99){
        x = 0;
        y = 0;
        z = 1;
        boundRebounceCount = 100;
      }

      else if(boundRebounceCount < 99){
        if(choice == 0){
          x = x - factor;
          boundRebounceCount++;
        }
        if(choice == 1){
          x = x + factor;
          boundRebounceCount++;
        }
        if(choice == 2){
          y = y - factor;
          boundRebounceCount++;
        }
        if(choice == 3){
          y = y + factor;
          boundRebounceCount++;
        }
        if(choice == 4){
          z = z + factor;
          boundRebounceCount++;
        }
        if(z >= 10 && choice == 5){
          z = z - factor;
          boundRebounceCount++;
        }
        else if(choice == 5){
          z = z + factor;
          boundRebounceCount++;
        }
      }

      return choice;
    }
  }

Output:

random walk 3D [boundary + clusters] 2.0

Random Walk 1.4.1
Inspired by “The Nature of Code” by Daniel Shiffman and it’s python translator Jake Hebbert.
Using C# in Grasshopper for Rhinoceros

//	Philipp Siedler
//	Daniel Shiffman "The Nature of Code"
//	Random Walk 1.4.1
 private void RunScript(int seed, int time, ref object A, ref object B, ref object C, ref object D, ref object E)
  {
    List <Point3d> pList = new List<Point3d>();
    List <Point3d> pListEx = new List<Point3d>();

    List <int> xList = new List<int>();
    List <int> indexList = new List<int>();

    Walker w = new Walker();
    Random random = new Random(seed);

    int counter = 0;
    indexList.Add(counter);

    for(int i = 0; i < time; i++){
      int rnd = random.Next(0, 6);
      w.step(rnd);

      if(w.boundRebounceCount < 100){
        pListEx.Add(w.pos());
      }
      else{
        pList.Add(w.pos());
      }
      counter++;


      if(indexList.Count() == 1){
        indexList[0] = counter;
      }

      if(w.x == 0 && w.y == 0 && w.z == 1){
        indexList.Add(counter);
        counter = 0;
      }
    }



    A = pList;
    B = xList;
    C = counter;
    D = indexList;
    E = pListEx;

  }

  // <Custom additional code> 
  public class Walker
  {
    public double x;
    public double y;
    public double z;
    public int bound;
    public int upperBound;
    public int rnd;
    public int boundRebounceCount;
    public int explosionNum;

    //Constructor that takes arguments.
    public Walker(){
      x = 1.0;
      y = 1.0;
      z = 1.0;
      bound = 10;
      upperBound = 100;
      rnd = 0;
      boundRebounceCount = 100;
    }

    public Point3d pos(){
      Point3d posPt = new Point3d(x, y, z);
      return posPt;
    }

    public int step(int rnd){

      int choice = rnd;
      int explosionNum = 0;

      //GROWING UP

      if(boundRebounceCount == 100){
        if (choice <= 0){
          x++;
        }
        else if(choice <= 1){
          x--;
        }
        else if(choice <= 2){
          y++;
        }
        else if(choice <= 3){ y--; } else if(z > 5 && choice <= 4){
          z--;
        }

        else if(choice <= 5){ z = z + 3; } if (x >= bound || x <= -bound){ boundRebounceCount = explosionNum; } if (y >= bound || y <= -bound){
          boundRebounceCount = explosionNum;
        }
        if (z <= 0 || z >= upperBound){
          boundRebounceCount = explosionNum;
        }
      }

      //EXPLODING
      double factor = 1;



      if(boundRebounceCount == 99){
        x = 0;
        y = 0;
        z = 1;
        boundRebounceCount = 100;
      }

      else if(boundRebounceCount < 99){ if(x >= -bound && choice == 0){
          x = x - factor;
          boundRebounceCount++;
        }
        else if(choice == 0){
          x = x + factor;
          boundRebounceCount++;
        }

        if(x <= bound && choice == 1){ x = x + factor; boundRebounceCount++; } else if(choice == 1){ x = x - factor; boundRebounceCount++; } if(y >= -bound && choice == 2){
          y = y - factor;
          boundRebounceCount++;
        }
        else if(choice == 2){
          y = y + factor;
          boundRebounceCount++;
        }

        if(y <= bound && choice == 3){
          y = y + factor;
          boundRebounceCount++;
        }
        else if(choice == 3){
          y = y - factor;
          boundRebounceCount++;
        }

        if(z <= upperBound && choice == 4){ z = z + factor; boundRebounceCount++; } else if(choice == 4){ z = z - factor; boundRebounceCount++; } if(z >= 10 && choice == 5){
          z = z - factor;
          boundRebounceCount++;
        }
        else if(choice == 5){
          z = z + factor;
          boundRebounceCount++;
        }
      }


      return choice;
    }
  }

Output: