# how do i generate random numbers in an interval?

ieatsoupwithafork
Posts:

**1**
in Propeller 1

Hi,

Title says all. I know the ? operator but I have no idea how to put it to practical use. Spin doesn't have a random function like I'm used to with other languages so I have no idea how and what to do with "?". Any help would be greatly appreciated.

Cheers!

Title says all. I know the ? operator but I have no idea how to put it to practical use. Spin doesn't have a random function like I'm used to with other languages so I have no idea how and what to do with "?". Any help would be greatly appreciated.

Cheers!

## Comments

11,866http://obex.parallax.com/object/498

11,86622,931It will return a random number between

loandhi - 1.-Phil

1,438Are you sure that's correct? Don't you need to strip the sign bit before the // in case the result of ?seed is negative? Otherwise, it will return numbers in the range (lo-(hi-lo+1), hi).

7,41922,931-Phil

82is there a way to randomize numbers from 1 to 70?

Thanks

7,419In the post above there is discussion about the randomize() method from the attached object. It would go like this:

`rval := prng.randomize(1, 70)`

Easy peasy.

428Hi

I wonder if you are asking for all the numbers 1 to 70 to be in a randomised order since getting a random number between 1 and 70 has already been explained.

If that is the case then build an array with the numbers 1 to 70 in it and starting at array item 1, exchange it with another number in the array, range 1-70 generated using the randomise function, and work your way through the whole array.

Dave