*rand Help

Ugh, I’m getting a Quicktest error. It just started out of the blue. Here’s my code:

*if (pottery>=1)
	*rand pottery_taken 0 pottery

Gives this error:


game_2 line 6493: Invalid rand statement, min must be less than max: 0 > -10

It’s definitely this line. But, how can pottery by -10 when I just made sure that it would be at least 1?

It is my understanding that you need to define the range, and -10 10 is the default of CS internally.

I have always defined the floor and the ceiling, and never had an issue.


1 Like

But it does have a defined range: 0 to pottery

When this error started, I put in the extra *if to make sure that the upper limit (pottery) is at least 1.

Can rand be a text variable?

Well, I am a novice scripter, so all I can do is shrug and look up as everything passes over my head :slight_smile:

Edit: this is not clear - I meant that I always though the definition had to be numerical, not text.


I am not sure why you are getting the error, I ran a test code and it seems to work fine.

From the error, it seems to think that pottery is -10, which should be impossible.
Can you try rewriting the pottery in rand?
it may be that it is not written properly.

@Lucid what is the value of pottery? in second case

1 Like

Yes, it can be variables.

This is strange.

So, this works:

*if (pottery<0)
*if (pottery<0)
	*set pottery 10
*rand pottery_taken 0 pottery

But this doesn’t:

*if (pottery<0)
*rand pottery_taken 0 pottery

pottery can’t be -10, yet the second set of commands still gets that error.

1 Like

The issue may be in the value of pottery variable prior to *if check. Had a similar error once: text variable’s length was interpreted as 0 symbols, even though the line was under condition *if length(variable)>2. Purely because the variable was created with value “” and later changed only through text input (without *set).

1 Like

I thought about that too, so I checked all *set pottery and *set pottery_taken

They all looked good. I had hoped that the conditional would grab that, but if it isn’t looking at the *if, I guess not.

It changes all the time, but it never gets below 0.

I did manage to replicate the error but only when the value was actually below zero.

So I am not sure why this is happening, can you show us the code leading to it?


This is the weirdest thing of all.
Well your first solution should work for it, good luck.

1 Like

No really. It’s a looping 13000 lines of code. :smiley:

I don’t believe pottery ever gets below 0. I have checks in place to catch it if it does, just in case. But, if the check RIGHT BEFORE the *rand doesn’t catch it, then I guess none of them will.

So strange, but yes, I have a work around. :slight_smile:


Unlike randomtest quicktest doesn’t actually execute your code properly, instead it does more “exploratory” testing. This can lead to some annoying false positives, like complaining about things that would not actually happen in a real run through. You can usually workaround this by adding missing conditionals, or changing the initial value of your variables.