0

I have a sample of 300 elements and I need a random vector of size 100000 which consists of random repetitions of the elements of the 300-element sample

I have tried the following

RandomSample[valueVector, 100000];

which returns the error

RandomSample::smplen: RandomSample cannot generate a sample of length 100000, which is greater than the length of the sample set {24741.5,20716.6,20850.3,20405.7,22293.1,46828.8,18963.4,25654.3,20767.4,22529.1,<<31>>,24440.8,22442.4,21309.6,25205.9,20810.9,20757.4,23551.3,22783.4,22674.8,<<250>>}. If you want a choice of possibly repeated elements from the set, use RandomChoice.

Can someone please suggest me how can I do this? should I use the RandomSample 333 times or is there a better way to do this?

slow_learner
  • 233
  • 1
  • 9
  • 3
    I voted to close this as "easily found in the documentation". If you are not yet used to checking the Details sections of the docs, make a habit of always looking there. – Szabolcs Nov 29 '22 at 12:12
  • A shame, the OP didn't even read the error, which includes "If you want a choice of possibly repeated elements from the set, use RandomChoice". Reading the documentation and all error codes surely takes less effort than posting a question. – rhermans Nov 29 '22 at 15:02

2 Answers2

2

Try RandomChoice

RandomChoice[valueVector , 100000 ]
Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
-2

I have managed with

RV = ConstantArray[1, 100000];
SeedRandom[1234];

For[i = 1, i < 100001, i++, RV[[i]] = RandomChoice[valueVector]];

slow_learner
  • 233
  • 1
  • 9
  • 4
    Since you are a beginner, it will be useful for your learning to completely forget that For loops even exist in Mathematica. https://mathematica.stackexchange.com/q/134609/12 – Szabolcs Nov 29 '22 at 12:13