Discussion:
Specific numbers but in a random sequence
(too old to reply)
Richard Ashbery
2019-06-21 20:31:03 UTC
Permalink
The following variables can be used to calculate precise angles
through which an object can be rotated. The first rotates object
through 360/3 = 120 degrees, the next one 360/4 = 90 degrees and so
on. Each calculation creates an integer with no decimal places.

3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120

I would like to be able to use these variables in a random sequence.
Has anyone a BASIC routine that could do this please?
Gavin Crawford
1970-01-01 00:00:00 UTC
Permalink
The following variables can be used to calculate precise anglesthrough which an object can be rotated. The first rotates objectthrough 360/3 = 120 degrees, the next one 360/4 = 90 degrees and soon. Each calculation creates an integer with no decimal places.3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be able to use these variables in a random sequence.Has anyone a BASIC routine that could do this please?
Why not put them into an array and use a random number to choose
the array index.
--
Gav
druck
2019-06-22 10:48:55 UTC
Permalink
Post by Gavin Crawford
The following variables can be used to calculate precise anglesthrough which an object can be rotated. The first rotates objectthrough 360/3 = 120 degrees, the next one 360/4 = 90 degrees and soon. Each calculation creates an integer with no decimal places.3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be able to use these variables in a random sequence.Has anyone a BASIC routine that could do this please?
Any reason 2 and 180 aren't used?
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.

IIRC to seed do RND(-TIME) before any other call to RND.

---druck
Richard Ashbery
2019-06-22 11:03:18 UTC
Permalink
Post by druck
Post by Gavin Crawford
Post by Richard Ashbery
The following variables can be used to calculate precise
anglesthrough which an object can be rotated. The first rotates
objectthrough 360/3 = 120 degrees, the next one 360/4 = 90
degrees and soon. Each calculation creates an integer with no
decimal places.3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I
would like to be able to use these variables in a random
sequence.Has anyone a BASIC routine that could do this please?
Any reason 2 and 180 aren't used?
Good question: 2 objects looked a little odd in the animation so I
went for 3 as a minimum.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Thanks guys for your help as always. The array method should work.
RND(-TIME) is a great idea to get non-repeating random numbers.

Many thanks

Richard
Richard Ashbery
2019-06-22 15:46:35 UTC
Permalink
[snip]

3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...

DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop

90 random numbers gives poor distribution:

3 x10
4 x14
5 x16
6 x8
8 x9
9 x4
10 x6
12 x3
15 x2
18 x3
20 x7
24 x7
30 x2
36 none
45 none
60 x2
90 none
120 x1

5 is repeated 3 times in a row.

Is there any way of improving it?

Richard
Someone Somewhere
2019-06-22 16:11:37 UTC
Permalink
Post by Richard Ashbery
[snip]
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop
3 x10
4 x14
5 x16
6 x8
8 x9
9 x4
10 x6
12 x3
15 x2
18 x3
20 x7
24 x7
30 x2
36 none
45 none
60 x2
90 none
120 x1
5 is repeated 3 times in a row.
Is there any way of improving it?
Does it always give such a poor distribution, even across multiple
runs? What about if you did RND(someBigNumber) MOD 18 ?
Richard Ashbery
2019-06-22 17:21:24 UTC
Permalink
Post by Someone Somewhere
Post by Richard Ashbery
[snip]
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop
[snip]
Post by Someone Somewhere
Post by Richard Ashbery
Is there any way of improving it?
Does it always give such a poor distribution, even across multiple
runs?
Yes
Post by Someone Somewhere
What about if you did RND(someBigNumber) MOD 18 ?
RND(500)MOD18 for example appears to improve the distribution. How
can I incorporate this idea with my 18 specific numbers in the array?

Richard
Steve Fryatt
2019-06-22 20:29:23 UTC
Permalink
On 22 Jun, Richard Ashbery wrote in message
RND(500)MOD18 for example appears to improve the distribution. How can I
incorporate this idea with my 18 specific numbers in the array?
You don't need to. Just do this:

DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(18))
NEXT I%
NEXT loop
--
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/
Richard Ashbery
2019-06-23 10:17:26 UTC
Permalink
Post by Steve Fryatt
On 22 Jun, Richard Ashbery wrote in message
RND(500)MOD18 for example appears to improve the distribution. How can I
incorporate this idea with my 18 specific numbers in the array?
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(18))
NEXT I%
NEXT loop
That's pretty much what I eventually arrived at. RND(18) makes other
variables appear in a more random distribution as other respondents
have pointed out earlier. There's only one problem which makes no
sense to me in that 3 never appears but 0 does.

Can others confirm please?

Richard
Ian
2019-06-23 11:07:36 UTC
Permalink
On Sun, 23 Jun 2019 11:17:26 +0100
Post by Richard Ashbery
Post by Steve Fryatt
On 22 Jun, Richard Ashbery wrote in message
Post by Richard Ashbery
RND(500)MOD18 for example appears to improve the distribution.
How can I incorporate this idea with my 18 specific numbers in
the array?
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(18))
NEXT I%
NEXT loop
That's pretty much what I eventually arrived at. RND(18) makes other
variables appear in a more random distribution as other respondents
have pointed out earlier. There's only one problem which makes no
sense to me in that 3 never appears but 0 does.
Can others confirm please?
The array%() is being initialised from (0) to (17). (18) would contain
the zero. (0) contains the three.

Random numbers are 1 to 18. So three doesn't appear, zero does.

Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.

I haven't tested it.

HTH,
Ian
Paul Oates
2019-06-23 12:17:55 UTC
Permalink
Post by Ian
On Sun, 23 Jun 2019 11:17:26 +0100
Post by Richard Ashbery
Post by Steve Fryatt
On 22 Jun, Richard Ashbery wrote in message
Post by Richard Ashbery
RND(500)MOD18 for example appears to improve the distribution.
How can I incorporate this idea with my 18 specific numbers in
the array?
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(18))
NEXT I%
NEXT loop
That's pretty much what I eventually arrived at. RND(18) makes other
variables appear in a more random distribution as other respondents
have pointed out earlier. There's only one problem which makes no
sense to me in that 3 never appears but 0 does.
Can others confirm please?
The array%() is being initialised from (0) to (17). (18) would contain
the zero. (0) contains the three.
Random numbers are 1 to 18. So three doesn't appear, zero does.
Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.
I haven't tested it.
HTH,
Ian
The array has 18 items, but the FOR...NEXT loop has 19. Perhaps it would
be as well to test the program by commenting out the 'PRINT array%
(RND(18))' and inserting 'PRINT loop, I%'. (just out of interest why is
'loop' not an Integer variable like I%?). Then when you are happy that the
loops are working you could revert. If you wanted, as an interim step
after testing the loops, you could replace '(RND(18))' with '(I%)' to
ensure all the entries in the array are produced.

regards
--
Paul Oates
***@btinternet.com
Steve Fryatt
2019-06-23 12:51:57 UTC
Permalink
On 23 Jun, Ian wrote in message
The array%() is being initialised from (0) to (17). (18) would contain the
zero. (0) contains the three.
Random numbers are 1 to 18. So three doesn't appear, zero does.
Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.
I haven't tested it.
HTH, Ian
It would be better to leave

array%()=3,4,5,6,8 ...

and then do

PRINT array%(RND(18) - 1)

however.
--
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/
Richard Ashbery
2019-06-23 13:10:43 UTC
Permalink
Post by Steve Fryatt
On 23 Jun, Ian wrote in message
Post by Ian
The array%() is being initialised from (0) to (17). (18) would
contain the zero. (0) contains the three.
Random numbers are 1 to 18. So three doesn't appear, zero does.
Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.
I haven't tested it.
HTH, Ian
It would be better to leave
array%()=3,4,5,6,8 ...
and then do
PRINT array%(RND(18) - 1)
No that doesn't work - it fails to take into account the last number in
the array (120). Ian's method does work with all numbers being randomly
displayed, albeit with some numbers displayed consecutively.

Regards

Richard
Steve Fryatt
2019-06-23 14:59:17 UTC
Permalink
On 23 Jun, Richard Ashbery wrote in message
Post by Richard Ashbery
Post by Steve Fryatt
On 23 Jun, Ian wrote in message
Post by Ian
The array%() is being initialised from (0) to (17). (18) would contain
the zero. (0) contains the three.
Random numbers are 1 to 18. So three doesn't appear, zero does.
Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.
I haven't tested it.
HTH, Ian
It would be better to leave
array%()=3,4,5,6,8 ...
and then do
PRINT array%(RND(18) - 1)
No that doesn't work - it fails to take into account the last number in
the array (120). Ian's method does work with all numbers being randomly
displayed, albeit with some numbers displayed consecutively.
In which case, are you sure that you're running the same code that you've
posted here?

I've just done the following:

numbers% = 18

DIM array%(numbers% - 1)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120

DIM bins%(numbers% - 1)
bins%() = 0

y = RND(-TIME)

FOR loop% = 1 TO 5
FOR I% = 0 TO 18
index% = RND(18) - 1
bins%(index%) += 1
PRINT "Index: ";index%,"Angle: ";array%(index%)
NEXT I%
NEXT loop%

FOR bin% = 0 TO numbers% - 1
PRINT "Bin ";bin%, "Value: ";array%(bin%), "Counts: ";bins%(bin%)
NEXT bin%

and it seems to do exactly what I'd expect...
--
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/
Richard Ashbery
2019-06-23 16:14:30 UTC
Permalink
Post by Steve Fryatt
On 23 Jun, Richard Ashbery wrote in message
[snip]
Post by Steve Fryatt
Post by Richard Ashbery
Post by Steve Fryatt
It would be better to leave
array%()=3,4,5,6,8 ...
and then do
PRINT array%(RND(18) - 1)
No that doesn't work - it fails to take into account the last
number in the array (120). Ian's method does work with all
numbers being randomly displayed, albeit with some numbers
displayed consecutively.
In which case, are you sure that you're running the same code that
you've posted here?
Sorry Steve - it appears you are correct - I was running old code.
It's not a good way but to see all the displayed output I ran the
program from a TaskObey file but I forgot to save the edited code
first before running.

Thanks for posting your program - the stats are really useful.

Apologies again

Richard
Richard Ashbery
2019-06-23 13:01:44 UTC
Permalink
Post by Ian
On Sun, 23 Jun 2019 11:17:26 +0100
[snip]
Post by Ian
Post by Richard Ashbery
Post by Richard Ashbery
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(18))
NEXT I%
NEXT loop
There's only one problem which makes no
sense to me in that 3 never appears but 0 does.
The array%() is being initialised from (0) to (17). (18) would contain
the zero. (0) contains the three.
Random numbers are 1 to 18. So three doesn't appear, zero does.
Add '0,' so that array%()=0,3,4,5,6,8 etc. and it should work.
I have and I've now got my 3 back - excellent. Nice explanation. I
haven't used arrays much so knowledge is lacking.

Richard
Paul Oates
2019-06-22 16:52:41 UTC
Permalink
Post by Richard Ashbery
[snip]
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop
3 x10
4 x14
5 x16
6 x8
8 x9
9 x4
10 x6
12 x3
15 x2
18 x3
20 x7
24 x7
30 x2
36 none
45 none
60 x2
90 none
120 x1
5 is repeated 3 times in a row.
Is there any way of improving it?
Richard
When I% is low doesn't RND(I%) give only a very limited choice; would
RND(18) be better?
--
Paul Oates
***@btinternet.com
Julian Fry
2019-06-22 16:56:16 UTC
Permalink
Post by Richard Ashbery
[snip]
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop
RND(N) where N>1 (N being an integer) returns a number between 1 and N
so you are resetting the range every call.
Try RND(18)
--
Best wishes

Julian

---
This email has been checked for viruses by AVG.
https://www.avg.com
Julian Fry
2019-06-22 17:05:32 UTC
Permalink
Post by Richard Ashbery
[snip]
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120I would like to be
able to use these variables in a random sequence.
Post by druck
Post by Gavin Crawford
Why not put them into an array and use a random number to choose
the array index.
Yes, and make sure you seed the random number generator, or it may
always go through the same pseudo random sequence each time its run.
IIRC to seed do RND(-TIME) before any other call to RND.
Not quite there yet - if I use the following...
DIM array%(18)
array%() = 3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
y = RND(-TIME)
FOR loop = 1 TO 5
FOR I% = 0 TO 18
PRINT array%(RND(I%))
NEXT I%
NEXT loop
RND(N) where N>1 (N being an integer) returns a number between 1 and N
so you are resetting the range every call.
Try RND(18)
--
Best wishes

Julian

---
This email has been checked for viruses by AVG.
https://www.avg.com
Sebastian Barthel
2019-06-24 07:37:30 UTC
Permalink
The following variables can be used to calculate precise angles through
which an object can be rotated. The first rotates object through 360/3 =
120 degrees, the next one 360/4 = 90 degrees and so on. Each calculation
creates an integer with no decimal places.
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
I would like to be able to use these variables in a random sequence.
Has anyone a BASIC routine that could do this please?
Is there a special reason why the "40" and "72" are missing in this line ?
If they would exist, the numbers may be seen as a symmetrical object with
its "half" between 18 and 20.
3,4,5,6,8,9,10,12,15,18,20,24,30,36,(40),45,60,(72),90,120
with 360/N

120,90,(72),60,45,40,36,30,24,20,18,15,12,10,(9),8,6,5,4,3


Therefore it probably could increase the "randomness" if You chosse to
calculate two random values:

the first one to choose from an array(N), with only the first ten numbers
in it, as described by many earlier.

the second random value as RND(2) which chooses the number N from the
array directly as the result if it is "1", otherwise, if it is "2", the
result is calculated as 360/N.


SBn
Richard Ashbery
2019-06-24 19:13:25 UTC
Permalink
Post by Sebastian Barthel
Post by Richard Ashbery
The following variables can be used to calculate precise angles
through which an object can be rotated. The first rotates object
through 360/3 = 120 degrees, the next one 360/4 = 90 degrees and
so on. Each calculation creates an integer with no decimal places.
3,4,5,6,8,9,10,12,15,18,20,24,30,36,45,60,90,120
I would like to be able to use these variables in a random
sequence. Has anyone a BASIC routine that could do this please?
Is there a special reason why the "40" and "72" are missing in this
line ? If they would exist, the numbers may be seen as a
symmetrical object with its "half" between 18 and 20.
My poor observation skills, I suspect. The first time I went down the
list to find only integers after the 360/N division - I must have
missed some. I have since added "IF 360 MOD N < 1" to print only
integers - should have done it earlier. Have now added 40 and 72 to
Steve's submission and 2 (Druck's suggestion) - thank you.
Post by Sebastian Barthel
Post by Richard Ashbery
3,4,5,6,8,9,10,12,15,18,20,24,30,36,(40),45,60,(72),90,120
with 360/N
120,90,(72),60,45,40,36,30,24,20,18,15,12,10,(9),8,6,5,4,3
Therefore it probably could increase the "randomness" if You chosse
the first one to choose from an array(N), with only the first ten
numbers in it, as described by many earlier.
the second random value as RND(2) which chooses the number N from
the array directly as the result if it is "1", otherwise, if it is
"2", the result is calculated as 360/N.
More knowledgeable programmers required to comment on this.

Richard

Loading...