Memory (strings). Random

I have a simple program that outputs one (of many) string messages via an output channel. The string values are maybe 40-50 chars or so.

I have no idea about how memory is used on the Imp. When should I get concerned about the number of possible string messages I have? I know 30 works fine. Will 50 be a problem? A 100? A 1,000?

Also, how random is " local r = math.rand()%29". I am not simulating a casino or anything like that, but over time will that statement produce 30 different integers (eventually)?

My simple code is near the bottom of http://whiskeytangohotel.com/ourcatdoor. (yes, I know a WHILE,/SWITCH/CASE method would be better but I couldn’t get it to work correctly)

Thanks.

In release-14, the imp has about 60K of free RAM available to Squirrel, though just loading Squirrel code eats into that somewhat. However, constant strings such as the ones in your code, are kept in Flash memory, not in RAM. The limit there is the limit on the total size of a compiled Squirrel program, which is 128K. If you have the Squirrel compiler installed on your PC, you can use that to check the compiled size of your Squirrel. (At least if it’s the 32-bit Squirrel compiler, which is the one that targets the imp.) There’s a bit of overhead, so you shouldn’t expect to fit quite as many as 128K/40=~3,000 snarky feline messages, but 1,000 should be OK.

The math.rand() function is provided by an LFSR, but it’s seeded every boot from a genuine hardware random number generator. So the randomness should be pretty good. Note, however, that “math.rand()%29” can only produce the integers 0,1,…,27,28 – a total of 29, not 30, distinct values.

Peter

peter:

Thank you very complete (and entertaining) answer. I don’t think I will ever be creative enough to think of 1000+ things a snarky feline could say, so we’re in good shape. :wink:

Thanks again.