$random() is not synthesisable, so i want the alternate for

  • Thread starter suprithaswamy@gmail.com
  • Start date
S

suprithaswamy@gmail.com

Guest
I need to generate a random number between 1 to 40 . without using the
$random() function , how will i generate it?
Heard that linear feedback shift register (LFSR) algorithm can be used
for this.
Can i know some details regarding this?
Or any other means for this random generation.
later, i may need to change the value 40 to 50 or to 60, how can i do
that?
 
LFSR can be used for "PSEUDO random number generator". It means that
the sequence will be the same for each initial value.
If you want to use REAL ramdom number generator you have to build it by
yourself or buy from others. It is not easy task.
 
Hi Michael,
thanks for your reply,

Let me make it clear, you mean to say that, for a
perticular initial value, i get the random sequence which is constant.
is it?
This would be fine.

But the problem is, if i want to generate random numbers between 1 to 4
or 1 to 8 or 1 to 16 or for the powers of 2, it would be easy.

I want to generate a random number between 1 to 40.

How do i do this?

If i use flops and tap at some perticular points and do some operations
on it and append that bit at the left extreem point, I will get random
number generated, but if it exceeds the top value(40), then its a
problem.

i want a solution for this.

thanks,
Supritha
 
<suprithaswamy@gmail.com> wrote in message
news:1141893979.201954.29340@i39g2000cwa.googlegroups.com...
I need to generate a random number between 1 to 40 . without using the
$random() function , how will i generate it?
Heard that linear feedback shift register (LFSR) algorithm can be used
for this.
Can i know some details regarding this?
Or any other means for this random generation.
later, i may need to change the value 40 to 50 or to 60, how can i do
that?
To understand "how random" you need your information, what's the
application? How often do you need validly random values generated?
 
Hi John,

Thanks for your reply,

Let me narrate my problem in an eloberate manner,

1)A number should get generated between 1 and 40 .
2) exculding the above generated number, a number should get generated
between 1 and 40 .
3) excluding the above two generated numbers, a number should get
generated between 1 and 40 .
..............................

In this fashion, all the possible numbers should get generated, later
the cycle can repeat......

can i use LFSR ?

If so, how can i?

Any other solution is also acceptable.


regards,
Supritha
 
suprithaswamy@gmail.com wrote:
Hi John,

Thanks for your reply,

Let me narrate my problem in an eloberate manner,

1)A number should get generated between 1 and 40 .
2) exculding the above generated number, a number should get generated
between 1 and 40 .
3) excluding the above two generated numbers, a number should get
generated between 1 and 40 .
.............................

In this fashion, all the possible numbers should get generated, later
the cycle can repeat......

can i use LFSR ?

If so, how can i?

Any other solution is also acceptable.


regards,
Supritha
If you're looking for a lottery picker, run a high speed counter that's
1-40 and stopped with the press of a button, then run the counter 1-39
for the press of the next button and add 1 if the count is greater than
the last number, and so on until the button-pushing user has randomly
selected the 6 winning lottery numbers.

There's no need to get fancy if the counter cycles 1000s of times a second.
 
Hi John,

This is not the case i wanted, i want to implement in
hardware.
So, i prefer using flops and some of the gates, so i think this lottery
picker will not help me in this regard.
I prefer LFSR because it is hardware friendly.
so can you tell me some solution considering my concerns.


regards,
Supritha
 
Dear Supritha ,

You could use something like that:

assign rng_number = (lfsr_out > 40) lfsr_out-40 : lfsr_out;

But again, LFSR is not the true RNG number.
If you use LFSR you should be very carefully with choosing the
configuration. Some configurations generate VERY short sequence. After
sequence is finished it will be started again and again.
 
Thanks michael,

Thanks for your suggesion, its working.

But as a add on, i dont want the random number repeat within the
sequence length.

Can u tell something regarding this.

Regards,
Supritha
 
Supritha,

You should look a little deeper into the workings of the LFSR.
It is possible to design LFSR's that are not maximal for a given
number of bits. Generally the maximal LFSR will have 2^n - 1
states for n bits, but with different feedback taps you can generate
other numbers of states. As far as I know, you need to experiment
to find the tap settings. I always got the tap settings for maximal
LFSR's from a table, but these tables were filled in by someone
who searched for them. I don't know of the existence of tables for
non-maximal LFSR's, but for one as short as 40 states it shouldn't
take too long to find one. Note that the 40 states you get in an
LFSR probably wouldn't be 1 through 40. Typically you could have
gaps in the sequence, but then you could add code to translate
values above 40 into the gaps.

Hope this helps,

Gabor

suprithaswamy@gmail.com wrote:
Hi John,

This is not the case i wanted, i want to implement in
hardware.
So, i prefer using flops and some of the gates, so i think this lottery
picker will not help me in this regard.
I prefer LFSR because it is hardware friendly.
so can you tell me some solution considering my concerns.


regards,
Supritha
 
Hi gabor,

Thanks for your suggession,

Note that the 40 states you get in an
LFSR probably wouldn't be 1 through 40. Typically you could have
gaps in the sequence, but then you could add code to translate
values above 40 into the gaps.
This is a part of your mail,

I am not clear what you mean to say.


can you please eloberate on this.

can you give me a example :) :)

small one, would be fine.

say for random generation between 1 and 12 :) :)

Thanks in advance.


regards,
Supritha
 
<suprithaswamy@gmail.com> wrote in message
news:1141963062.971581.102580@v46g2000cwv.googlegroups.com...
Hi John,

Thanks for your reply,

Let me narrate my problem in an eloberate manner,

1)A number should get generated between 1 and 40 .
2) exculding the above generated number, a number should get generated
between 1 and 40 .
3) excluding the above two generated numbers, a number should get
generated between 1 and 40 .
.............................

In this fashion, all the possible numbers should get generated, later
the cycle can repeat......

can i use LFSR ?

If so, how can i?

Any other solution is also acceptable.


regards,
Supritha
Since the lottery picker is not your application, I will reassert my
comment:

To help find a solution for "how random" you need your data, the
application - not the routine - would help to understand your needs. If the
multiple random numbers have to be one clock cycle after the other your
needs are much different than if you have a push-button to manually select
each number. Even a new number every 1000 clock cycles will present
non-random sets of numbers if you use a small LFSR.

So again,
What's your application?
How often do you need a new random number?
 
<suprithaswamy@gmail.com> wrote in message
news:1141963062.971581.102580@v46g2000cwv.googlegroups.com...
Hi John,

Thanks for your reply,

Let me narrate my problem in an eloberate manner,

1)A number should get generated between 1 and 40 .
2) exculding the above generated number, a number should get generated
between 1 and 40 .
3) excluding the above two generated numbers, a number should get
generated between 1 and 40 .
.............................

In this fashion, all the possible numbers should get generated, later
the cycle can repeat......

can i use LFSR ?

If so, how can i?

Any other solution is also acceptable.


regards,
Supritha
Since the lottery picker is not your application, I will reassert my
comment:

To help find a solution for "how random" you need your data, the
application - not the routine - would help to understand your needs. If the
multiple random numbers have to be one clock cycle after the other your
needs are much different than if you have a push-button to manually select
each number. Even a new number every 1000 clock cycles will present
non-random sets of numbers if you use a small LFSR.

So again,
What's your application?
How often do you need a new random number?
 
hi John,

i'm doing a data transfer operation, in which i may have a
maximum latency of 40 cycles.
so now i need to generate a sequence of random number from 1 to 40, to
check the working of the latency.
for the purpose of optimization, i dont want the numbers to get
repeated within the sequence.
after the sequence of random numbers get over, the same sequence can
repeat.

This is the explanation for my problem.

Thanks & Regards,
Supritha
 
Will the RNG be part of your desing or testbench?
If it is testbench you could use $random.
 
Hi michael,

Random numbers are to be generated in design.
I wish i could use $random in my design also :( :(

This is the problem now.

waiting for your suggessions.

Regards,
Supritha
 
To get REAL random number generator you have to build it by yourself
(as we did) or to buy from third party provider. There are not much
generators in the market.
 
Supritha,

If you take a 4-bit LFSR and use XOR feedback on taps 1 and 4, you
will get a 15-state sequence utilizing values 1 through 15 (note that
with
XOR feedback you can't use state 0 without extra logic).

Now if instead you take feedback from taps 2 and 4, you only get
a 6-state sequence 15, 14, 12, 9, 3, 7 (decimal). Note that although
all of the bits change you don't get all of the possible values. Now
you would need some way to map these six values into a contiguous
set to use them more easily. You could do this with a small ROM
or look-up table.

By the way, once you decide to use a mapping (i.e. ROM) from the
generated values to the actual values, you may as well start with a
simple binary counter.

Also note that a pseudorandom pattern may repeat in more than
the number of output states. For example you could have a pattern
generator that repeats only after 400 samples, but only outputs
values 1 to 40. I would guess that for your test circuit this sort
of generator may be more useful, since it allows you to use different
transitions into the same state. For example if you are testing
and have a problem going from 3 to 40, you would not necessarily
catch this problem if your "random" number generator repeats after
40 states, possibly entering state 40 always after state 7, for
instance.

Good luck,
Gabor

suprithaswamy@gmail.com wrote:
Hi gabor,

Thanks for your suggession,

Note that the 40 states you get in an
LFSR probably wouldn't be 1 through 40. Typically you could have
gaps in the sequence, but then you could add code to translate
values above 40 into the gaps.

This is a part of your mail,

I am not clear what you mean to say.


can you please eloberate on this.

can you give me a example :) :)

small one, would be fine.

say for random generation between 1 and 12 :) :)

Thanks in advance.


regards,
Supritha
 
"suprithaswamy@gmail.com" <suprithaswamy@gmail.com> writes:

hi John,

i'm doing a data transfer operation, in which i may have a
maximum latency of 40 cycles.
so now i need to generate a sequence of random number from 1 to 40, to
check the working of the latency.
for the purpose of optimization, i dont want the numbers to get
repeated within the sequence.
after the sequence of random numbers get over, the same sequence can
repeat.

This is the explanation for my problem.
It doesn't seem that they have to be that random, so why not just
write yourself an array of numbers by hand that is as "random" as you
like and follows the rules.

or indeed, can you just use a counter from 1 to 40?

Cheers,
Martin

--
martin.j.thompson@trw.com
TRW Conekt - Consultancy in Engineering, Knowledge and Technology
http://www.trw.com/conekt
 
Hi Michael,

My one of the requriment is satisfied, i.e, numbers
between 1 and 40.
One the thing is i dont want random numbers to repeat within the
sequence.
We cant purchase from vendors, because its not affordable.


Waiting for your suggessions.

regards,
Supritha
 

Welcome to EDABoard.com

Sponsor

Back
Top