Generate 100 data randomly, or select if it is possible

纵然是瞬间 提交于 2019-12-20 05:57:27

问题


I want to test my model , I need to test it in some data , I want to generate data , in fact I want to have 125 different parameter from 0 to 10000.

For example , in below we have 4 different parameter ,from 1 to 300.

 Set I/0*300/;
 Parameter MyParameter;
 MyParameter /4 1,10 1,42 1,87 1/;

I don't want to do this by hand.

Is there any method that I generate it automaticly.

another way asking:

how can Select 4 random element of a set ' I' , without repetition?


回答1:


Try this:

Set       I     /0*300/
          picks /p1*p4/;
Scalar    pick;
Parameter MyParameter(I);

MyParameter(I) = 0;
loop(picks,
  pick = uniformInt(1, card(I));

* Make sure to not pick the same one twice
  while(sum(I$(pick=ord(I)),MyParameter(I))=1,
    pick = uniformInt(1, card(I))
    Display 'here';
  );

  MyParameter(I)$(pick=ord(I))=1;
);
Display MyParameter;


来源:https://stackoverflow.com/questions/52028444/generate-100-data-randomly-or-select-if-it-is-possible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!