Advertisement
Regela

Random Json Generator

Mar 15th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1.  
  2. int my_rand() {
  3.   srand( millis() + rand() );
  4.   return rand();
  5. }
  6. //char* unsigned int a) {
  7. //  char *ret = "";
  8. //  for (int i = 1; a >= i; i *= 10) {
  9. //    ret = strcat('0' + (a / i % 10), ret);
  10. //  }
  11. //  return ret;
  12. //}
  13. void echo(char* str) {
  14.   Serial.print(str);
  15.   delay(100);
  16. }
  17. void echo(int a) {
  18.   Serial.print(a);
  19.   delay(100);
  20. }
  21.  
  22. void random_json() {
  23.   int count = my_rand() % 45 + 5;
  24.   int time[count];
  25.   time[0] = my_rand() % 10000 + 1000;
  26.   for (int i = 1; i < count; i++) {
  27.     time[i] = time[i - 1] + my_rand() % 3000 + 100;
  28.   }
  29. //  char* buff=new char[32];
  30.   echo("{\"A\":{\"mKeys\":[");
  31.   echo(time[0]);
  32.  
  33.   for (int i = 1; i < count; i++) {
  34.     echo(",");
  35.     echo(time[i]);
  36.   }
  37.   echo("],\"mValues\":[");
  38.   echo(my_rand() % 1000 + 500);
  39.   for (int i = 1; i < count; i++) {
  40.     echo(",");
  41.     echo(my_rand() % 1000 + 500);
  42.   }
  43.   echo("],\"mSize\":");
  44.   echo(count);
  45.   echo("},\"P\":{\"mKeys\":[");
  46.   echo(time[0]);
  47.   for (int i = 1; i < count; i++) {
  48.     echo(",");
  49.     echo(time[i]);
  50.   }
  51.   echo("],\"mValues\":[");
  52.   echo(my_rand() % 60000 + 90000);
  53.   for (int i = 1; i < count; i++) {
  54.     echo(","); echo(my_rand() % 60000 + 90000);
  55.   }
  56.   echo("],\"mSize\":");
  57.   echo(count);
  58.   echo("}}");
  59. }
  60.  
  61. char* one_of_3_json() {
  62.   switch (my_rand() % 5) {
  63.     case 0: {
  64.         return "{\"A\":{\"mKeys\":[1,2,3,4],\"mValues\":[1,2,3,4],\"mSize\":4},\"P\":{\"mKeys\":[1,2,3,4],\"mValues\":[1,2,3,4],\"mSize\":4}}";
  65.       }
  66.     case 1: {
  67.         return "{\"A\":{\"mKeys\":[3010,3110,3211,3311,3412,3512,3613,3713,3814,3914],\"mValues\":[500,600,800,1000,1200,1400,1300,1100,900,500],\"mSize\":10},\"P\":{\"mKeys\":[3010,3110,3211,3311,3412,3512,3613,3713,3814,3914],\"mValues\":[100000,110000,120000,130000,140000,150000,140000,130000,120000,110000],\"mSize\":10}}";
  68.       }
  69.     case 2: {
  70.         return "{\"A\":{\"mKeys\":[3010,3110,3211,3311,3412,3512,3613,3713,3814,3914,4015,4115,4217,4317,4420],\"mValues\":[500,900,1200,1500,1600,1600,1600,1500,1400,1300,1200,1100,900,700,500],\"mSize\":15},\"P\":{\"mKeys\":[3010,3110,3211,3311,3412,3512,3613,3713,3814,3914],\"mValues\":[100000,120000,140000,150000,150000,150000,150000,150000,150000,140000,130000,120000,120000,110000,100000],\"mSize\":15}}";
  71.       }
  72.   }
  73. }
  74.  
  75.  
  76. void setup() {
  77.   // put your setup code here, to run once:
  78.   Serial.begin(9600);
  79.  
  80.  
  81. }
  82.  
  83. void loop() {
  84.   // put your main code here, to run repeatedly:
  85.   Serial.println("dsf");
  86.   random_json();
  87.  
  88. //  char* buff=new char[32];
  89. //echo(my_rand()%1000);
  90.   delay(100);
  91.  
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement