int my_rand() {
srand( millis() + rand() );
return rand();
}
//char* unsigned int a) {
// char *ret = "";
// for (int i = 1; a >= i; i *= 10) {
// ret = strcat('0' + (a / i % 10), ret);
// }
// return ret;
//}
void echo(char* str) {
Serial.print(str);
delay(100);
}
void echo(int a) {
Serial.print(a);
delay(100);
}
void random_json() {
int count = my_rand() % 45 + 5;
int time[count];
time[0] = my_rand() % 10000 + 1000;
for (int i = 1; i < count; i++) {
time[i] = time[i - 1] + my_rand() % 3000 + 100;
}
// char* buff=new char[32];
echo("{\"A\":{\"mKeys\":[");
echo(time[0]);
for (int i = 1; i < count; i++) {
echo(",");
echo(time[i]);
}
echo("],\"mValues\":[");
echo(my_rand() % 1000 + 500);
for (int i = 1; i < count; i++) {
echo(",");
echo(my_rand() % 1000 + 500);
}
echo("],\"mSize\":");
echo(count);
echo("},\"P\":{\"mKeys\":[");
echo(time[0]);
for (int i = 1; i < count; i++) {
echo(",");
echo(time[i]);
}
echo("],\"mValues\":[");
echo(my_rand() % 60000 + 90000);
for (int i = 1; i < count; i++) {
echo(","); echo(my_rand() % 60000 + 90000);
}
echo("],\"mSize\":");
echo(count);
echo("}}");
}
char* one_of_3_json() {
switch (my_rand() % 5) {
case 0: {
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}}";
}
case 1: {
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}}";
}
case 2: {
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}}";
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("dsf");
random_json();
// char* buff=new char[32];
//echo(my_rand()%1000);
delay(100);
}
Comments