Start a new topic
Solved

Editor crashes when triying to get a RANDOM value

Hi comunity!


I'm triying to get a simple random value; but every time I try, Nextion Editor crashes.


My test is very simple. When Touch on page0:


va0.val=rand


Compilation are OK, but on debug screen editor crashes and goes down.


I assuming rand is the correct instruction to get a random value

On Nexiton commads help only show ranset to set random value límits, but I understand is not necessary to call it before rand command (crashes anyway...)


I'm running Nextion Editor V0.35 under Windows 10


Some help? it will be a bug or I'm doing something wrong?


Thanks!



It would be my understanding that randset is undefined (could be anything including zeros) if you have not specifically set it.  randset=n command gives the top value, and rand will pick a number from 0 to (n-1).  I certainly would expect to have crashes and unknown results when told to set randset before use and skipping initialization processes.


va0.val=rand will have absolutely no idea of what the expected range to select from.


Place a randset=(your_highest_value+1) in your Page0 PreInitialization Event and your issue will more than likely go away.  There will be a slight difference between handling "undefined value" inside the Nextion Editor hardware, but predicted that .NET has initialized to zero.  Therefore, an raised exception should be the expected default behaviour from skipping this randset command.



Hi Patrick!


Thanks for answer; but is not necessary to call RANDSET before generate a random value, it assumes a value calculation between 0 and 4294967295 (explained at Nextion instruction Set)

When I triying, Nextion editor (always) crashes calling RANDSET or not.


But... now, under Editor V0.36 works correctly; bug has been fixed...   :-)



Glad it worked out for you.  Good programming practices would be to set your range before a call to randset before a call to rand (unless 32bit unsigned 4294967295 was the exact range you were looking for).  Why leave it to chance ... c'est la vie.