Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - uniform does not give required results

 
Thread Tools Search this Thread
Old 08-25-2008, 06:54 PM   #1
Default uniform does not give required results


Hi All


Im using ncvhdl version 6.11. For some reason, the uniform function
suddenly does not work as required. The seed value does not change on
different calls to the uniform function. I have debugged my program to
find out the error but have not been successful. So, I have to write a
random generator function (that need not be synthesized). Could
somebody please tell me what algorithm to use for the same?


Thanks,

PS: This is not part of any homework/school work


indu
  Reply With Quote
Old 08-25-2008, 07:31 PM   #2
Mike Treseler
 
Posts: n/a
Default Re: uniform does not give required results
indu wrote:

> Im using ncvhdl version 6.11. For some reason, the uniform function
> suddenly does not work as required. The seed value does not change on
> different calls to the uniform function.



http://groups.google.com/groups/?q=v...clare+variable


Mike Treseler
  Reply With Quote
Old 08-25-2008, 08:29 PM   #3
indu
 
Posts: n/a
Default Re: uniform does not give required results
Thanks. I have initialised it but the seed does not seem to be
changing.

Im pasting a snippet of my code.

procedure random_vector(
variable seed1 :inout integer;
variable seed2 :inout integer;
variable vmax : in integer;
variable result : out integer ) is

variable x : real;
begin
UNIFORM(seed1,seed2,x);
i := integer(x) mod vmax;
result := i;
end procedure random_vector;
begin
xx: process is
....
....
variable seed1, seed2 : integer := 1
random_vector(seed1 => seed1, seed2 => seed2, vmax, x=>x);

....
end process

When I run this behavorial code, I see that the value of seed does not
change between calls. Am I doing something wrong here?

Thanks,


On Aug 25, 2:31 pm, Mike Treseler <mtrese...@gmail.com> wrote:
> indu wrote:
> > Im using ncvhdl version 6.11. For some reason, the uniform function
> > suddenly does not work as required. The seed value does not change on
> > different calls to the uniform function.

>
> http://groups.google.com/groups/?q=v...clare+variable




indu
  Reply With Quote
Old 08-25-2008, 09:59 PM   #4
Mike Treseler
 
Posts: n/a
Default Re: uniform does not give required results
indu wrote:
> Thanks. I have initialised it but the seed does not seem to be
> changing.


Your procedure is out of process scope.
Maybe test it without a procedure first.

-- Mike T

xx: process is
variable ...
-- <----procedure declaration goes here
-- other declarations
begin
-- ...


Mike Treseler
  Reply With Quote
Old 08-26-2008, 03:12 PM   #5
Tricky
 
Posts: n/a
Default Re: uniform does not give required results
On 25 Aug, 20:29, indu <sangeethasn...@gmail.com> wrote:
> Thanks. I have initialised it but the seed does not seem to be
> changing.
>
> Im pasting a snippet of my code.
>
> procedure random_vector(
> * variable seed1 :inout integer;
> * variable seed2 :inout integer;
> * variable vmax * : in integer;
> * variable result : out integer ) is
>
> * *variable x : real;
> * *begin
> * * * * UNIFORM(seed1,seed2,x);
> * * * * i := integer(x) mod vmax;
> * * * * result := i;
> * end procedure random_vector;
> begin
> xx: process is
> ...
> ...
> variable seed1, seed2 *: integer := 1
> random_vector(seed1 => seed1, seed2 => seed2, vmax, x=>x);
>
> ...
> end process
>
> When I run this behavorial code, I see that the value of seed does not
> change between calls. Am I doing something wrong here?
>
> Thanks,
>


The seed values have to be possitive, but this should only throw an
error rather than not work at all, but you have a problem with the x
output from the UNIFORM function.

> UNIFORM(seed1,seed2,x);
> i := integer(x) mod vmax;
> result := i;


X is a real value that will be a value between 0 and 1. casting it to
and integer will then just result in 0 or 1, and overall your "result"
value will end up just being 0 or 1, regardless of VMAX. You need to
take the returned x value and use that the scale the return value to
something more meaningful. It is best to work with real types until
the very end.

In the words of blue peter: here's one I prepared earlier:

procedure rand_int( variable seed1, seed2 : inout positive;
min, max : in integer; --
boundaries for the random result (inclusive)
result : out integer) is
variable rand : real;
begin
uniform(seed1, seed2, rand);
result := integer(
real(min) --set the base
+ (rand * (real(max)-real(min)) ) -- add in the random
offset from the base, over a given range.
);
end procedure;


Tricky
  Reply With Quote
Old 08-26-2008, 04:07 PM   #6
indu
 
Posts: n/a
Default Re: uniform does not give required results
Thanks Tricky. You are right. I dint realise that at all.

On Aug 26, 10:12 am, Tricky <Trickyh...@gmail.com> wrote:
> On 25 Aug, 20:29, indu <sangeethasn...@gmail.com> wrote:
>
>
>
> > Thanks. I have initialised it but the seed does not seem to be
> > changing.

>
> > Im pasting a snippet of my code.

>
> > procedure random_vector(
> > variableseed1 :inout integer;
> > variableseed2 :inout integer;
> > variablevmax : in integer;
> > variableresult : out integer ) is

>
> > variablex : real;
> > begin
> > UNIFORM(seed1,seed2,x);
> > i := integer(x) mod vmax;
> > result := i;
> > end procedure random_vector;
> > begin
> > xx: process is
> > ...
> > ...
> >variableseed1, seed2 : integer := 1
> > random_vector(seed1 => seed1, seed2 => seed2, vmax, x=>x);

>
> > ...
> > end process

>
> > When I run this behavorial code, I see that the value of seed does not
> > change between calls. Am I doing something wrong here?

>
> > Thanks,

>
> The seed values have to be possitive, but this should only throw an
> error rather than not work at all, but you have a problem with the x
> output from theUNIFORMfunction.
>
> > UNIFORM(seed1,seed2,x);
> > i := integer(x) mod vmax;
> > result := i;

>
> X is a real value that will be a value between 0 and 1. casting it to
> and integer will then just result in 0 or 1, and overall your "result"
> value will end up just being 0 or 1, regardless of VMAX. You need to
> take the returned x value and use that the scale the return value to
> something more meaningful. It is best to work with real types until
> the very end.
>
> In the words of blue peter: here's one I prepared earlier:
>
> procedure rand_int(variableseed1, seed2 : inout positive;
> min, max : in integer; --
> boundaries for the random result (inclusive)
> result : out integer) is
> variablerand : real;
> begin
> uniform(seed1, seed2, rand);
> result := integer(
> real(min) --set the base
> + (rand * (real(max)-real(min)) ) -- add in the random
> offset from the base, over a given range.
> );
> end procedure;




indu
  Reply With Quote
Old 08-26-2008, 04:08 PM   #7
indu
 
Posts: n/a
Default Re: uniform does not give required results
Thanks Tricky. You are right. I dint realise that at all.

On Aug 26, 10:12 am, Tricky <Trickyh...@gmail.com> wrote:
> On 25 Aug, 20:29, indu <sangeethasn...@gmail.com> wrote:
>
>
>
> > Thanks. I have initialised it but the seed does not seem to be
> > changing.

>
> > Im pasting a snippet of my code.

>
> > procedure random_vector(
> > variableseed1 :inout integer;
> > variableseed2 :inout integer;
> > variablevmax : in integer;
> > variableresult : out integer ) is

>
> > variablex : real;
> > begin
> > UNIFORM(seed1,seed2,x);
> > i := integer(x) mod vmax;
> > result := i;
> > end procedure random_vector;
> > begin
> > xx: process is
> > ...
> > ...
> >variableseed1, seed2 : integer := 1
> > random_vector(seed1 => seed1, seed2 => seed2, vmax, x=>x);

>
> > ...
> > end process

>
> > When I run this behavorial code, I see that the value of seed does not
> > change between calls. Am I doing something wrong here?

>
> > Thanks,

>
> The seed values have to be possitive, but this should only throw an
> error rather than not work at all, but you have a problem with the x
> output from theUNIFORMfunction.
>
> > UNIFORM(seed1,seed2,x);
> > i := integer(x) mod vmax;
> > result := i;

>
> X is a real value that will be a value between 0 and 1. casting it to
> and integer will then just result in 0 or 1, and overall your "result"
> value will end up just being 0 or 1, regardless of VMAX. You need to
> take the returned x value and use that the scale the return value to
> something more meaningful. It is best to work with real types until
> the very end.
>
> In the words of blue peter: here's one I prepared earlier:
>
> procedure rand_int(variableseed1, seed2 : inout positive;
> min, max : in integer; --
> boundaries for the random result (inclusive)
> result : out integer) is
> variablerand : real;
> begin
> uniform(seed1, seed2, rand);
> result := integer(
> real(min) --set the base
> + (rand * (real(max)-real(min)) ) -- add in the random
> offset from the base, over a given range.
> );
> end procedure;




indu
  Reply With Quote
Old 08-27-2008, 08:50 AM   #8
Tricky
 
Posts: n/a
Default Re: uniform does not give required results
No Problem

One thing I didnt realise till yesterday - MIN and MAX are inclusive
boundaries, but do not have the same distribution as the other values.
eg:

MIN = 0, MAX = 5

over 100 repetitions, mean distribution is:

0 = 10
1 = 20
2 = 20
3 = 20
4 = 20
5 = 10

To make it evenly distributed, you'll need to + or - 0.5 from the end
result before converting to an integer. This will make it exclusive of
min (+0.5) or max (-0.5). For most useful purposes, it shouldnt really
matter though.


Tricky
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
java applet and accesing results from a database Ayesha General Help Related Topics 0 08-12-2009 04:15 PM
Mcse,Mcsa,Mcitp,Mcts,Mcdst,Mcpd @Home..Without Tests And Study(PayAfter Check Results on MCP Site) cert_king1@yahoo.com MCITP 0 01-23-2009 09:38 AM
Obatin MCSE,CCNA,CCNP,ORACLE,JAVA And Many More Certs WithoutExams..Pay After Check Results..100% Passing Gaurantee certexpert MCTS 0 01-16-2009 12:41 PM
Obtain Mcse,Ccna,Ccnp Without Exams( Pay After Check Results) 100%Passing Gaurantee Scr MCTS 0 06-19-2008 08:50 AM
Obtain All COMPTIA Certificaitons Without Exams....100% Passing Gaurantee...Pay After Check Results.... Certificaitons Without Exams A+ Certification 0 09-25-2006 10:19 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46