I'm desenvolving an APP for EuroMillions Lottery in my m5stack and I have some troubles with it and I hope someone will help me.

I sort n times a number between 1 and 50 (the Euromillions Lottery range of numbers). Every time a number is sorted, an array with 50 elements is incremented at the number sorted position. If 5 is sorted, then MatrixNumber[5]=MatrixNumber[5]+1. After n times I will seek the MatrixNumber[] and search for the biggest number there and the corresponding position where I found it and save the position in another array (FinalNumber[]). After that I zeroe the position so that it only be only one maximum values for all the array. (are you lost? I hope not). After all is done I get an array with 5 numbers (the most sorted by function "random(50)+1". I do the ssame stuff for the "Stars" part of the sorting.

Problem ONE: I can't SORT the array from lesser to bigger. I've done everything and it just don't sort.

Problem TWO: In "option" I use a number that can be "-2" to "+2". That number will be added the the "sorted number" comparing his value. For example, variable "Option1" value will be added if a number is sorted between 1 and 6 and "Option2" value will be added to numkber sorted if the number is between 7 and 12, ... and so on (1..6,7..12,13..18,... are the lines on the lottery form). If I change the number to any row (row 1 to 8) beside value "00", the sorting is giving me almost always the same numbers. If I put the rows to position value of "00" then it's random again.

Very weird.

I copied the source code in pastebin because it's kind of big and I want to share the code anyway (but not with weird stuff on it).

https://pastebin.com/LBpKVPcv

Can anyone help?

NOW the "random" numbers are "random" even with "tweaks" actives. Thanks for your support and help. Any sugestions/remarks are welcome as always. ]]>

I loaded your code into arduino (1.8.12) and tried to compile it.

The verifying of your code stopped at line 248 where you have an

**exit;** statement. So the code you submitted above cannot be the code running on your M5Stack.

The right syntax of your code should be **exit(0);**

Do you really want that ? see

https://forum.arduino.cc/index.php?topic=216073.0

On the arduino, calling exit(0) really isn't a useful thing to do.

On Arduino, the statement **exit(0)** translates to

cli(); // disable interrupts

while(1); // loop forever

So it basically stops your program running, but leaves your CPU running in an infinite loop ! So your programm gets stuck in your getEuromillionOptions(); subroutine until you switch it off.

Sorry, it will take some time for me to figure out, what your code is supposed to do and what it is doing.

Good practice is to write the code with comments where you are explaining what the different variables are and what the different sections are supposed to do. In old days writing code where you jumped in and out in different sections spaghetti code (you do that when you press a key A,B,C on your M5Stack).

In Arduino you have to cut your code into different sections and the look, if the sections are doing what they are supposed to. In most programs in arduino you insert a "serial.println(x,y,z)" at the end of each section. Before running your program you open a terminal on the com line your ESP32 is connected to. That way for each code snipped you can check, if x,y,z are the values the program should furnish.

By the way, as I understand from your code, your supposed random numbers are no random numbers any more:

Starting you set all your MatrixNumber(1-50) to 1; then you generate 25000 times a random variable x (Temp1); you modify the variable x with your options (-2,-1,0,1,2) (=Temp2) and adjust the values of new x (Temp2) to 1-50; then you increment MatrixNumber(x) by 1 (25000 times); as I see it, your MatrixNumber(1-50) should then be 25000/50= ~500. So you are testing the randomness oft he random number generator instead generating random numbers ! In mathematics it's called the Monte Carlo Method: If you play roulette 25000 times, statistically all numbers drawn should be equal. I several numbers are drawn more frequent than they should be statistically, there must be a flaw in the roulette spinning machine. Players analyzing this behavior of the roulette spinning machine can then set their chips on these numbers trying using it to their advatage breaking the bank.

crami25

]]>I still don't understand what you want to do ....maybe you could explain it in your native language.

You are always speaking of sorting and you are using the verb for different purposes:

sorting : sort 5 numbers so the lowest is displayed first and the highest last (5,7,28,35,47)

tip : the 5 numbers you want to fill into the euromillion form

draw: the 5 numbers which are drawn in the euromillion lottery

you probably use sorting for all three different arrays of values

I also don't understand your tweak -2..+2 system: The numbers drawn have nothing to do with the rows in the euromillion form. If the lowest number you tip is a 5 and the lowest number drawn is 15 your tweak according your explanation would be -10 ???

The type of the euromillions forms probably depends on the country you are playing:

In Spain, Germany the first row has the numbers 1-5 (not 6) and in France 1-10 !

In my opinion the rows in the form have nothing to do with the the numbers drawn and and the numbers you have tipped: You have to tip 5 different numbers from 1-50. The rows of the form is only a convenient way displaying the numbers (1-50 in ten rows of 5, 1-50 in five rows of 10, 1-50 in seven rows of six and a last row of the remaining 49 and 50). This country dependend form-scheme is only used to be read by the scanner entering your tip into the euromillions lottery.

Crami25

]]>Hello,

I have looked at your programm and I really don't understand what you are trying to do :

Storing and retrieving datas from eprom ? Displaying battery levels ? Randomly reading keypresses ? Generating negative numbers (with signed char) ? Mixing char, integers and long integers ? Some weird sorting scheme ?

So what is the goal of your app ? You are only talking about some weird sorting problems where nobody understands what you want to do.

For each line in the euromillions lottery you have to enter 5 different numbers between 1 and 50, and 2 different numbers for the stars between 1 and 12.

Probably you want to generate the 5 numbers and the 2 stars with a random number generator and display it on your m5Stack lcd. So your programm would look like:

- Setup : Start the (pseudo) random number generator (seed)
- On a keypress: Generate 5 numbers and 2 stars:

- generate 5 numbers between 1 and 50; as long as 2 numbers are equal replace it with a new random number; sort the numbers low to high eg. by bubble sort; display the numbers;

- generate 2 (star)numbers between 1 and 12; as long as the two numbers are equal replace one with a new random number; if number 2 < number 1 switch the numbers; display the numbers on the lcd.

If you are new to programming with arduino and C++ instead of trying to copy and paste some demo codes, try to programm your app with blockly/(Micropython) : flow.m5stack.com .

There you can generate random numbers, lists with 5 and 2 elements and do the sorting with the logic elements and display the results (as labels) on your M5Stack lcd,

Good luck!

crami25