[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [oc] Again! modulo arithmetic hardware




I like the solution!

maybe it would be easier to implement it like this:

static int temp = 0;
int random ()
{
  int x = rand16() + temp;
  if (x >= 10) x -= 10;
  if (x >= 10) x -= 10;
  return temp = x;
}

Is this distribution still flat and random?

Marko

> You have to add memory to get a soluton:
>
> What you can for example do is to generate a 4-bit number.
> For numbers 0..9 you output the actual value.
> For number 10 you output 0 for the first time and 5 for the second time it
> appears.
> For number 11 you output 1 for the first time and 6 for the second time it
> appears.
> For number 12 you output 2 for the first time and 7 for the second time it
> appears.
> For number 13 you output 3 for the first time and 8 for the second time it
> appears.
> For number 14 you output 4 for the first time and 9 for the second time it
> appears.
> For number 15 you output 0 for the first time, 1 for the second, etc. 15
for
> the 15th time.
>
> You can implement that with some registers/counters and a few logic. This
> will give you true flat distribution - if I'm right - without having large
> inputs and slow modulo logic.
>
> Andras Tantos


--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml