# Generating random samples from normal distributions with parameters coming from a list

MustarandSigmastar = Join[Mustar, VectorofSigmastar];
z = Table[
RandomVariate[
NormalDistribution[MustarandSigmastar[[i]],
MustarandSigmastar[[j]]], n], {i, 1, m}, {j, m + 1, 2m}];


How to generate only m pairs of parameters? Thanks

• Which pairs do you want? Do you want pairs like {first, 1+mth}, {second,2+mth}, etc? Also, please fix your code by providing definitions for all symbols. Without this, we're left making our own test cases and guessing what those should be for your context. And speaking of test cases, sample inputs with expected outputs would make it even clearer what you're hoping to achieve. Dec 10, 2022 at 19:29
• Please post an example. Dec 11, 2022 at 2:28

## 3 Answers

m = 10;
mustar = RandomReal[{-1, 1}, m]
sigmastar = RandomReal[{0, 1}, m]
z = MapThread[RandomVariate[NormalDistribution[#1, #2]] &, {mustar, sigmastar}]


Make RandomVariate pick as many as you wish. If you meant that you wanted existing parameter lists to be randomly paired, just replace mustar with RandomSample@mustar.

Clear["Global*"]

m = 5;
n = 4;

MustarandSigmastar = RandomReal[1, 2 m];

param =
RandomChoice[
Outer[{#1, #2} &,
MustarandSigmastar[[;; m]],
MustarandSigmastar[[m + 1 ;;]]] //
Flatten[#, 1] &,
m];

z = RandomVariate[
NormalDistribution @@ #, n] & /@
param

(* {{0.707468, 0.736669, 0.708138, 0.721982},
{0.40102, 0.430933, 0.425616, 0.414167},
{0.557164, 0.480605, 0.523246, 0.462627},
{0.711562, 0.710971, 0.780158, 0.665663},
{1.17702, 1.01058, 0.908726, 0.706781}} *)

MustarandSigmastar = Inner[List, Mustar, Sigmastar, List];
z = Table[
RandomVariate[
NormalDistribution[MustarandSigmastar[[i]][[1]],
MustarandSigmastar[[i]][[2]]], n], {i, 1, m}];

(This is how I addressed it.)
`
• Simpler and more idiomatic approaches are available.
– Alan
Dec 12, 2022 at 14:13