# Help request understanding the use of SeedRandom [closed]

I want to use SeedRandom inside of a code in which I use SmoothKernelDistribution to obtain the pdf of a stochastic process at a determined time as empiricPDF1 = SmoothKernelDistribution[RandomVariable1Histogram] Then, I want to do a Monte Carlo of the resulting random variable as d1 = RandomVariate[empiricPDF1, 100000];. Unfortunately, this code takes a lot of time to run and I get different results each time that I execute it.

I need someone to help me to understand how to use SeedRandom so that I don't have to generate a sample of 100k random numbers inside of d1 and instead always get the same 100k random numbers so that d1 always has the same values and hopefuly I also get a smaller running time.

• You simply need to write e.g. "SeedRandom[1]". E.g.: SeedRandom[1]; RandomVariate[NormalDistribution[0, 1], {2}] Commented Dec 15, 2021 at 8:36
• @DanielHuber. Thanks for the answer. However, I am having another issue. I have written SeedRandom[1]; RandomVariate[empiricPDF1, {100}], obtaining what I want. Hoever, I cannot seem to use it anywhere. d1 = SeedRandom[1]; retuns the error Part::partd: Part specification d1[[1]] is longer than depth of object. and imis = Table[ isexpan /. {z1 -> SeedRandom[1][[k]], z2 -> SeedRandom[1][[k]]}, {k, 1, nsim}]; also returns the same error. Can you please offer me further help? Commented Dec 15, 2021 at 8:55
• Say you want 100 real numbers. Then you write: SeedRandom[1]; data=RandomVariate[NormalDistribution[0, 1], {100}] Commented Dec 15, 2021 at 10:37
• , I don't get how can I store the results": the result is stored in d1. Further, a second run should take the same time. "SeedRandom[1]" should not get an error, it resets the random number generator. Commented Dec 15, 2021 at 13:42
• (1) You're having trouble with your code, but nobody can guess what code you are executing. The code you show in your comments (except for the Table[..] in the first one) do not give errors when run in a fresh kernel. To get useful help, post self-contained code that reproduces the error(s). (2) It's not entirely clear what you want. If you want the table of random values to persist from one kernel session to the next, look up LocalSymbol and consider using LocalSymbol["d1"] instead of d1. You might be interested in DumpSave and Save. Commented Dec 15, 2021 at 14:39