Trying to generate and save a random number in TinyDB

Happy Sunday,

If anyone reading this would take a moment and tell me what I have misunderstood, I would appreciate it. In my tiny mind, the attached if statement (located in the When Screen1.Initialize block) should look for a previously stored random number and, if that number is not found, generate a random number between one and ten million. That randomly generated number should be saved back to TinyDB for future logins and displayed in my User_ID.Text label but it is not showing up. Thank you, in advance, for any eagle-eyes who can spot my error.

The purpose of this is to assign a permanent (fixed) number to each user the first time the app is opened. That random number will be used as a impersonal identifier in a data base to determine how often the app is used, as every user will have his or her unique randomly-generated identifier.

Your TinyDB tag should be the literal piece of text "USERID".
The value under that unchanging tag should be the user ID number you assigned.

What you were using for a tag was the number 0, which is quite uninformative.

BTW, Clock1.SystemTime makes for a good unpredictable large user ID number too.

Regards,
0

Hi, and thank you for your reply. I am not sure I have it, yet. Correction - I am sure I don't have it yet. Anything that I plug in to the global variable shows up in my text label. I am not yet generating anything but incorrect answers.

Untitled

You can initialize that UserID global variable to the phrase 'I don't know my User ID yet'

When I recommend you use a constant piece of text as a tag, that recommendation applies to all cases where you will store or retrieve that piece of information.

Now show me your 0.

This should do it:

1 Like

Hi, Kind of.

This seems to generate a random number in the range upon downloading the app but that number is lost when the app is powered down. When I power up again, there is no new random number but the previously generated number is nowhere to be found. Does this tell me that nothing was stored?

how do you know nothing was stored?any blocks to prove that?
what about use ' if then else' block?

That's not what @TIMAI2 coded.

Hi,

OK - I finally saw the problem - another order of operations error. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.