Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- FPGAs and Programmable Solutions
- Programmable Devices
- Pseudo-random Number Generator

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
11:25 AM

2,100 Views

Pseudo-random Number Generator

Hi,

I have looking for a Pseudo-random number generator with some maximum linit. I know the LFSR approach but I dont know how to limit the maximum number generated by the LFSR. For example if I want to use an 8-bit LFSR with maximum limit of 200. How to limit the LFSR so that number must not exceed 200. Any link, idea or circuit will be highly appreciated Thanks Ali Umair
12 Replies

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
12:11 PM

Re: Pseudo-random Number Generator

You can't.

If the number is out of range, discard it and request another until you get one in range.
Highlighted
##

--- Quote Start --- If the number is out of range, discard it and request another until you get one in range. --- Quote End --- This way an undefinite number of cycles is possibly required before you get a valid result. If you can't allow this, because you need the random number immediately, you must implement a different solution. If you don't bother the indipendence between successive pseudo-random numbers, you can simply feed the LFSR output to a modulo 200 adder: you sum the previous number to the LFSR result, divide by 200 and take the remainder, which is actually a pseudo random number uniformly distributed between 0 and 199.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
02:16 PM

Re: Pseudo-random Number Generator

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
02:28 PM

Re: Pseudo-random Number Generator

Infinite is an exaggeration :-) Especially if the source is an LFSR.

Highlighted
##

--- Quote Start --- Infinite is an exaggeration :-) Especially if the source is an LFSR. --- Quote End --- Infact I said undefinite, not infinite. I mean it could require one cycle (in about 80% of cases), two retries (16%), three (3.2%, right?) and so on.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
02:35 PM

Re: Pseudo-random Number Generator

Highlighted
##

*lfsr_out* is the output of your LFSR and *result* is what you are looking for.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
03:12 PM

Re: Pseudo-random Number Generator

In theory, you need to change your lfsr_out to the range of 0 to 1 (1 not included) and then scale it by (limit + 1). In your 8-bit case:

wire [15:0] temp = lfsr_out * 16'd201; wire [7:0] result = temp [15:8];
Highlighted
##

*lfsr_out* is the output of your LFSR and *result* is what you are looking for. --- Quote End --- This way you'll get a non uniform distribution, namely some values would be much more frequent than others, expecially if LFSR output range is not a lot bigger than the desired range. Extending the LFSR length would help improving the distribution.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
03:44 PM

Re: Pseudo-random Number Generator

--- Quote Start --- In theory, you need to change your lfsr_out to the range of 0 to 1 (1 not included) and then scale it by (limit + 1). In your 8-bit case: wire [15:0] temp = lfsr_out * 16'd201; wire [7:0] result = temp [15:8];

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
04:03 PM

Re: Pseudo-random Number Generator

55 values would appear twice as often as the other 201 - regardless of the LFSR length.

Highlighted
##

You are correct. I made the assumption that the implementation was not meant to pass any such tests as chi-squared or others, given the small size of the sampling field. I could be wrong.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
04:07 PM

Re: Pseudo-random Number Generator

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
04:32 PM

Re: Pseudo-random Number Generator

Yes, it does rather depend on what sort of random numbers you want!

Highlighted
##

--- Quote Start --- Yes, it does rather depend on what sort of random numbers you want! --- Quote End --- one other method is to get your values in software(e.g. matlab) of any range you choose then store them in LUT and run it from there. As such you can choose whatever type of random values are available in the tool.

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-19-2012
07:43 PM

Re: Pseudo-random Number Generator

Highlighted
##

I think the scaling method is good enough for me to use in my design. Another question is, how I can add the lower limit? i.e. how can i generate a random number that should be less than 200 but greater than 50?

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-20-2012
01:55 PM

Re: Pseudo-random Number Generator

Highlighted
##

Altera_Forum

Valued Contributor III

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-20-2012
02:21 PM

Re: Pseudo-random Number Generator

Simply scale to 150 and add 50 to the result.