Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #5770 > unrolled thread

Specific numbers but in a random sequence

Started byRichard Ashbery <basura@invalid.addr.uk>
First post2019-06-21 21:31 +0100
Last post2019-06-24 20:13 +0100
Articles 20 on this page of 21 — 10 participants

Back to article view | Back to comp.sys.acorn.programmer


Contents

  Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-21 21:31 +0100
    Re:Specific numbers but in a random sequence Gavin Crawford <gc@dentrassis.com> - 2019-06-21 22:27 +0100
      Re: Specific numbers but in a random sequence druck <news@druck.org.uk> - 2019-06-22 11:48 +0100
        Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-22 12:03 +0100
        Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-22 16:46 +0100
          Re: Specific numbers but in a random sequence Someone Somewhere <nntpac@gmail.com> - 2019-06-22 17:11 +0100
            Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-22 18:21 +0100
              Re: Specific numbers but in a random sequence Steve Fryatt <news@stevefryatt.org.uk> - 2019-06-22 21:29 +0100
                Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-23 11:17 +0100
                  Re: Specific numbers but in a random sequence Ian <Ian.Hamilton@AAUG.net> - 2019-06-23 12:07 +0100
                    Re: Specific numbers but in a random sequence Paul Oates <oatespaul@btinternet.com> - 2019-06-23 13:17 +0100
                    Re: Specific numbers but in a random sequence Steve Fryatt <news@stevefryatt.org.uk> - 2019-06-23 13:51 +0100
                      Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-23 14:10 +0100
                        Re: Specific numbers but in a random sequence Steve Fryatt <news@stevefryatt.org.uk> - 2019-06-23 15:59 +0100
                          Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-23 17:14 +0100
                    Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-23 14:01 +0100
          Re: Specific numbers but in a random sequence Paul Oates <oatespaul@btinternet.com> - 2019-06-22 17:52 +0100
          Re: Specific numbers but in a random sequence Julian Fry <julianfry@orpheusmail.co.uk> - 2019-06-22 17:56 +0100
          Re: Specific numbers but in a random sequence Julian Fry <JulianFry@compuserve.com> - 2019-06-22 18:05 +0100
    Re: Specific numbers but in a random sequence Sebastian Barthel <naitsabes@freenet.de> - 2019-06-24 07:37 +0000
      Re: Specific numbers but in a random sequence Richard Ashbery <basura@invalid.addr.uk> - 2019-06-24 20:13 +0100

Page 1 of 2  [1] 2  Next page →


#5770 — Specific numbers but in a random sequence

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-21 21:31 +0100
SubjectSpecific numbers but in a random sequence
Message-ID<57c7c5d6c0basura@invalid.addr.uk>
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?

[toc] | [next] | [standalone]


#5771

FromGavin Crawford <gc@dentrassis.com>
Date2019-06-21 22:27 +0100
Message-ID<qeji40$7ca$1@dont-email.me>
In reply to#5770
Richard Ashbery <basura@invalid.addr.uk> Wrote in message:
> 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

[toc] | [prev] | [next] | [standalone]


#5772

Fromdruck <news@druck.org.uk>
Date2019-06-22 11:48 +0100
Message-ID<qel12p$ibq$1@dont-email.me>
In reply to#5771
On 21/06/2019 22:27, Gavin Crawford wrote:
> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:
>> 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?

> 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

[toc] | [prev] | [next] | [standalone]


#5773

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-22 12:03 +0100
Message-ID<57c815b263basura@invalid.addr.uk>
In reply to#5772
In article <qel12p$ibq$1@dont-email.me>, druck <news@druck.org.uk>
wrote:
> On 21/06/2019 22:27, Gavin Crawford wrote:
> > Richard Ashbery <basura@invalid.addr.uk> Wrote in message:
> >> 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.

> > 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

[toc] | [prev] | [next] | [standalone]


#5774

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-22 16:46 +0100
Message-ID<57c82fa1bdbasura@invalid.addr.uk>
In reply to#5772
In article <qel12p$ibq$1@dont-email.me>,
   druck <news@druck.org.uk> wrote:
> On 21/06/2019 22:27, Gavin Crawford wrote:
> > Richard Ashbery <basura@invalid.addr.uk> Wrote in message:

[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.

> > 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

[toc] | [prev] | [next] | [standalone]


#5775

FromSomeone Somewhere <nntpac@gmail.com>
Date2019-06-22 17:11 +0100
Message-ID<qeljvl$1i81$1@gioia.aioe.org>
In reply to#5774
On 22/06/2019 16:46, Richard Ashbery wrote:
> In article <qel12p$ibq$1@dont-email.me>,
>     druck <news@druck.org.uk> wrote:
>> On 21/06/2019 22:27, Gavin Crawford wrote:
>>> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:
> 
> [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.
> 
>>> 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?
> 
Does it always give such a poor distribution,  even across multiple 
runs?    What about if you did RND(someBigNumber) MOD 18 ?

[toc] | [prev] | [next] | [standalone]


#5778

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-22 18:21 +0100
Message-ID<57c8384f3bbasura@invalid.addr.uk>
In reply to#5775
In article <qeljvl$1i81$1@gioia.aioe.org>,
   Someone Somewhere <nntpac@gmail.com> wrote:
> On 22/06/2019 16:46, Richard Ashbery wrote:
> > In article <qel12p$ibq$1@dont-email.me>,
> >     druck <news@druck.org.uk> wrote:
> >> On 21/06/2019 22:27, Gavin Crawford wrote:
> >>> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:
> > 
> > [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.
> > 
> >>> 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:

[snip]

> > 
> > Is there any way of improving it?
> > 
> Does it always give such a poor distribution,  even across multiple 
> runs?    

Yes

> 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

[toc] | [prev] | [next] | [standalone]


#5780

FromSteve Fryatt <news@stevefryatt.org.uk>
Date2019-06-22 21:29 +0100
Message-ID<mpro.ptiowz0137v62032t.news@stevefryatt.org.uk>
In reply to#5778
On 22 Jun, Richard Ashbery wrote in message
    <57c8384f3bbasura@invalid.addr.uk>:

> 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/

[toc] | [prev] | [next] | [standalone]


#5781

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-23 11:17 +0100
Message-ID<57c8955578basura@invalid.addr.uk>
In reply to#5780
In article <mpro.ptiowz0137v62032t.news@stevefryatt.org.uk>,
   Steve Fryatt <news@stevefryatt.org.uk> wrote:
> On 22 Jun, Richard Ashbery wrote in message
>     <57c8384f3bbasura@invalid.addr.uk>:

> > 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

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

[toc] | [prev] | [next] | [standalone]


#5782

FromIan <Ian.Hamilton@AAUG.net>
Date2019-06-23 12:07 +0100
Message-ID<20190623120736.3390b842@ian-460-p050na>
In reply to#5781
On Sun, 23 Jun 2019 11:17:26 +0100
Richard Ashbery <basura@invalid.addr.uk> wrote:

> In article <mpro.ptiowz0137v62032t.news@stevefryatt.org.uk>,
>    Steve Fryatt <news@stevefryatt.org.uk> wrote:
> > On 22 Jun, Richard Ashbery wrote in message
> >     <57c8384f3bbasura@invalid.addr.uk>:  
> 
> > > 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  
> 
> 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

[toc] | [prev] | [next] | [standalone]


#5783

FromPaul Oates <oatespaul@btinternet.com>
Date2019-06-23 13:17 +0100
Message-ID<0f5da0c857.Paul@oatespaul.btinternet.com>
In reply to#5782
In message <20190623120736.3390b842@ian-460-p050na>
          Ian <Ian.Hamilton@AAUG.net> wrote:

> On Sun, 23 Jun 2019 11:17:26 +0100
> Richard Ashbery <basura@invalid.addr.uk> wrote:

>> In article <mpro.ptiowz0137v62032t.news@stevefryatt.org.uk>,
>>    Steve Fryatt <news@stevefryatt.org.uk> wrote:
>>> On 22 Jun, Richard Ashbery wrote in message
>>>     <57c8384f3bbasura@invalid.addr.uk>:
>> 
>>>> 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
>> 
>> 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
oatespaul@btinternet.com

[toc] | [prev] | [next] | [standalone]


#5784

FromSteve Fryatt <news@stevefryatt.org.uk>
Date2019-06-23 13:51 +0100
Message-ID<mpro.ptjyef01sni5u02sz.news@stevefryatt.org.uk>
In reply to#5782
On 23 Jun, Ian wrote in message
    <20190623120736.3390b842@ian-460-p050na>:

> 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/

[toc] | [prev] | [next] | [standalone]


#5786

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-23 14:10 +0100
Message-ID<57c8a5327abasura@invalid.addr.uk>
In reply to#5784
In article <mpro.ptjyef01sni5u02sz.news@stevefryatt.org.uk>, Steve
Fryatt <news@stevefryatt.org.uk> wrote:
> On 23 Jun, Ian wrote in message
>     <20190623120736.3390b842@ian-460-p050na>:

> > 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

[toc] | [prev] | [next] | [standalone]


#5787

FromSteve Fryatt <news@stevefryatt.org.uk>
Date2019-06-23 15:59 +0100
Message-ID<mpro.ptk4an02tw93i02sz.news@stevefryatt.org.uk>
In reply to#5786
On 23 Jun, Richard Ashbery wrote in message
    <57c8a5327abasura@invalid.addr.uk>:

> In article <mpro.ptjyef01sni5u02sz.news@stevefryatt.org.uk>, Steve Fryatt
> <news@stevefryatt.org.uk> wrote:
> > On 23 Jun, Ian wrote in message
> >     <20190623120736.3390b842@ian-460-p050na>:
> 
> > > 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/

[toc] | [prev] | [next] | [standalone]


#5788

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-23 17:14 +0100
Message-ID<57c8b60602basura@invalid.addr.uk>
In reply to#5787
In article <mpro.ptk4an02tw93i02sz.news@stevefryatt.org.uk>, Steve
Fryatt <news@stevefryatt.org.uk> wrote:
> On 23 Jun, Richard Ashbery wrote in message

[snip]

> > 
> > > 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

[toc] | [prev] | [next] | [standalone]


#5785

FromRichard Ashbery <basura@invalid.addr.uk>
Date2019-06-23 14:01 +0100
Message-ID<57c8a45ff1basura@invalid.addr.uk>
In reply to#5782
In article <20190623120736.3390b842@ian-460-p050na>,
   Ian <Ian.Hamilton@AAUG.net> wrote:
> On Sun, 23 Jun 2019 11:17:26 +0100
> Richard Ashbery <basura@invalid.addr.uk> wrote:

[snip]

> > > 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

[toc] | [prev] | [next] | [standalone]


#5776

FromPaul Oates <oatespaul@btinternet.com>
Date2019-06-22 17:52 +0100
Message-ID<ceae35c857.Paul@oatespaul.btinternet.com>
In reply to#5774
In message <57c82fa1bdbasura@invalid.addr.uk>
          Richard Ashbery <basura@invalid.addr.uk> wrote:

> In article <qel12p$ibq$1@dont-email.me>,
>    druck <news@druck.org.uk> wrote:
>> On 21/06/2019 22:27, Gavin Crawford wrote:
>>> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:

> [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.

>>> 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

When I% is low doesn't RND(I%) give only a very limited choice; would 
RND(18) be better?


-- 
Paul Oates
oatespaul@btinternet.com

[toc] | [prev] | [next] | [standalone]


#5777

FromJulian Fry <julianfry@orpheusmail.co.uk>
Date2019-06-22 17:56 +0100
Message-ID<0a0336c857.Root@julianfry.orpheusnet.co.uk>
In reply to#5774
On 22 Jun 2019 Richard Ashbery  wrote:

> In article <qel12p$ibq$1@dont-email.me>,
>    druck <news@druck.org.uk> wrote:
>> On 21/06/2019 22:27, Gavin Crawford wrote:
>>> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:

> [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.

>>> 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

[toc] | [prev] | [next] | [standalone]


#5779

FromJulian Fry <JulianFry@compuserve.com>
Date2019-06-22 18:05 +0100
Message-ID<17dc36c857.Root@julianfry.orpheusnet.co.uk>
In reply to#5774
On 22 Jun 2019 Richard Ashbery  wrote:

> In article <qel12p$ibq$1@dont-email.me>,
>    druck <news@druck.org.uk> wrote:
>> On 21/06/2019 22:27, Gavin Crawford wrote:
>>> Richard Ashbery <basura@invalid.addr.uk> Wrote in message:

> [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.

>>> 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

[toc] | [prev] | [next] | [standalone]


#5789

FromSebastian Barthel <naitsabes@freenet.de>
Date2019-06-24 07:37 +0000
Message-ID<qepujq$a34$1@solani.org>
In reply to#5770
Am Fri, 21 Jun 2019 21:31:03 +0100 schrieb 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.

> 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

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.sys.acorn.programmer


csiph-web