0

I generated a 2d random array in $x-y$ plane with

L = 10;
random = Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, L, L/10}, {y, 0, L, L/10}];

Now I want to save it for the next using by

iniF = Interpolation[Flatten[random, 1]];
inif[x_, y_] = c+iniF[x, y];

where $c$ is constant. How do you save the random data with a convenient format? Thank you!

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
lxy
  • 165
  • 5
  • 19

2 Answers2

6

Add this simple code before u run everything will let Random generate exactly the same result every time you run. If you're careful enough, you may find this in lot's of posts with randomly generated input.

SeedRandom["Whatever you write here, keep it the same in multiple runs!"]

Hope this can help you!

Wjx
  • 9,558
  • 1
  • 34
  • 70
4

As a general solution, you can always Export you data to a file.

L = 10;
random = Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, L, L/10}, {y, 0, L, L/10}];

Export[NotebookDirectory[]<>"rand.dat",Flatten[random,1]]

Next time you want to use this data

random = Import[NotebookDirectory[]<>"rand.dat"];

One benefit of using data file is you can use the data with any other language as well and also share with others. If you are working only with MMA, using a Seed as suggested by Wjx would be a better option.

Sumit
  • 15,912
  • 2
  • 31
  • 73