Using the random() in LiveCode

803 views Asked by At

I have an issue with using

the random defined function in livecode.

Here is a code snippet:

// 97 -> 122 = lower case...
put random(97,122) into randASCII

The program is to create an order number, the order number consists of the first character of the first name, first character of last name, random number between 1 and 9, and a random ASCII value between 97 and 122 (the lower case characters.)

Thank you very much!

4

There are 4 answers

1
dunbarx On

Try this, assuming you have your list of names in fld 1:

on mouseUp
  put fld 1 into temp
  repeat with y = 1 to the number of lines of temp
    put char 1 of word 1 of line y of temp & char 1 of last word of line y of temp & random(9) & numToChar(96 + random(26)) into line y of orderList 
  end repeat
  answer orderList
end mouseUp
0
makeshyft_tom On

Although your question is not totally clear, I believe what you want is

 put numtonativechar(randomInRange(97,122)) into randASCII

EDIT: in LiveCode to generate a random number between 2 numbers you need this function first

function randomInRange lowerLimit,upperLimit
   return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
0
makeshyft_tom On

Just adding a note here that 9007199254740993 is the max random number from which LC can select from. Its known as the last safe int.

1
torocruzand On

If we have the limits. We just have to look for the difference between them. That is the parameter that we pass to the random () function and then we add the lower limit to it.

function randomInRange lowerLimit,upperLimit
   return  lowerLimit + random(upperLimit - lowerLimit)
end randomInRange