Wednesday, 16 December 2015

Randsequence in SystemVerilog

The random sequence generator is useful for randomly generating structured sequences of stimulus such as instructions or network traffic patterns.
By randomizing a packet, it will generate most unlikely scenarios which are not interested. These type of sequence of scenarios can be generated using randsequence.

randsequence is composed of one or more productions.
Each production contains a name and one or more production_list.

Production_list contains one or more production_item.
Production_items of production_list are further classified into terminals and non-terminals.
Non-terminals are defined in terms of terminals and other non-terminals.
A terminal is an indivisible item that needs no further definition than its associated code block.
Ultimately, every non-terminal is decomposed into its terminals.

module rand_sequence1();
initial begin
repeat(5) begin
randsequence( main )
main : one two three ;
one : {$write("one");};
two : {$write(" two");};
three: {$display(" three");};
endsequence
end
end
endmodule : rand_sequence1
// Here production is "main".
// production "main" contain only one production_list with 3 production_items named "one", "two", "three".
// production_items "one", "two", "three" are terminals.
// When the "main" is chosen, it will select the sequence "one", "two" and "three" in order.
//Output:
// one two three
// one two three
// one two three
// one two three
// one two three




A single production can contain multiple production lists.
multiple production lists are separated by the | symbol.
Production lists separated by a | imply a set of choices, which the generator will make at random.

module rand_sequence2();
initial begin
repeat(8) begin
randsequence( main )
main : one | two | three ;
one : {$display("one");};
two : {$display("two");};
three: {$display("three");};
endsequence
end
end
endmodule : rand_sequence2
// Here "main" is production,
// "main" has 3 production_list, each production_list consist 1 production_item,
// 1st production_list has a production_item called "one",
// 2nd production_list has a production_item called "two",
// 3rd production_list has a production_item called "three",
// production_items "one", "two", "three" all are terminals.
//Output:
// three
// three
// one
// two
// three
// two
// two
// one
//Results show that one, two and three are selected randomly.




By default procution_list is generated randomly, you can give probability for a production_list generation.
The probability that a production list is generated can be changed by assigning weights to production lists.
The probability that a particular production list is generated is proportional to its specified weight.
The := operator assigns the weight specified by the weight_specification to its production list.
A weight_specification must evaluate to an integral non-negative value.
Weight expressions are evaluated when their enclosing production is selected, thus allowing weights to change dynamically.

module rand_sequence3();
integer one_1,two_2,three_3;
initial begin
one_1 = 0;
two_2 = 0;
three_3 = 0;
repeat(6000) begin
randsequence( main )
main : one := 1 | two := 2 | three := 3;
one : {one_1++;};
two : {two_2++;};
three: {three_3++;};
endsequence
end
$display(" one %0d \n two %0d \n three %0d",one_1,two_2,three_3);
end
endmodule : rand_sequence3
//Output:
// one 1044
// two 1970
// three 2986




A production can be made conditional by means of an if..else production statement.
The expression can be any expression that evaluates to a boolean value. If the expression evaluates to true, the production following the expression is generated, otherwise the production following the optional else statement is generated.

module rand_sequence4();
integer one_1,two_2,three_3;
reg on;
initial begin
on = 0;
one_1 = 0;
two_2 = 0;
three_3 = 0;
repeat(2500) begin
randsequence( main )
main : one three;
one : {if(on) one_1++; else two_2 ++; };
three: {three_3++;};
endsequence
end
$display(" one %0d \n two %0d \n three %0d",one_1,two_2,three_3);
end
endmodule : rand_sequence4
//Output:
// one 0
// two 2500
// three 2500


module rand_sequence4a();
integer one_1,two_2,three_3;
reg on;
initial begin
on = 0;
one_1 = 0;
two_2 = 0;
three_3 = 0;
repeat(2500) begin
randsequence( main )
main : one three;
one : if(on) incr_one else incr_two;
incr_one : {one_1 += 2; one_1--;};
incr_two : {two_2 += 2; two_2--;};
three: {three_3++;};
endsequence
end
$display(" one %0d \n two %0d \n three %0d",one_1,two_2,three_3);
end
endmodule : rand_sequence4a
//Output:
// one 0
// two 2500
// three 2500




A production can be selected from a set of alternatives using a case production statement.
The case expression is evaluated, and its value is compared against the value of each case-item expression, which are evaluated and compared in the order in which they are given.
The production associated with the first case-item expression that matches the case expression is generated.
If no matching case-item expression is found then the production associated with the optional default item is generated, or nothing if there no default item.
Case-item expressions separated by commas allow multiple expressions to share the production.

module rand_sequence5();
integer one_1,two_2,three_3;
initial begin
for(int i = 0 ;i < 10 ;i++)
begin
randsequence( main )
main : case(i%3)
0 : zero;
1, 2 : non_zero;
default : def;
endcase;
zero : {$display("zero");};
non_zero : {$display("non_zero");};
def : {$display("default");};
endsequence
end
end
endmodule : rand_sequence5
//Output:
// zero
// non_zero
// non_zero
// zero
// non_zero
// non_zero
// zero
// non_zero
// non_zero
// zero




The repeat production statement is used to iterate a production over a specified number of times.

module rand_sequence6();
integer one_1,two_2,three_3;
initial begin
one_1 = 0;
two_2 = 0;
three_3 = 0;
repeat(6000) begin
randsequence( main )
main : one | repeat(2) two | repeat(3) three ;
one : {one_1 ++; };
two : {two_2 ++; };
three: {three_3 ++; };
endsequence
end
$display(" one %d \n two %d \n three %d",one_1,two_2,three_3);
end
endmodule : rand_sequence6
//Output:
// one 2059
// two 4072
// three 5715

22 comments:

  1. engineering personal statements is giving one of the best opportunity to achieve a best website which will be very powerful for the students. I really like your post!

    ReplyDelete
  2. Essay writing tests the talents of a author in several sides of the language that he's writing upon. AN essay author is also a student World Health Organization is writing the essay as a section of educational curricula or knowledgeable essay author writing on a subject for business. here

    ReplyDelete
  3. This blog is provide so informative information. It’s important when you write ATS. It’s really so helpful. If you don’t belief me then you can visit this site for your confirmation. It’s help you too.
    my blog

    ReplyDelete
  4. Awesome blog and nice information. Thanks

    ReplyDelete
  5. Great I'm Very glad to Read Your post about Randsequence in SystemVerilog, Thank You Very Much For This Articles To Share With Us. That Was An Informative. This Is Probably The Best By Far Statistics Sop Sequence. Easy To Understand and Educate Myself. Love Your Post Always Verification Random Sequence Creator. Keep Share Your Creative Technique Really Appreciate.

    ReplyDelete
  6. Randsequence in SystemVerilog is nice topic.This blog is provide so informative information. It’s important when you write ATS. It’s really so helpful. If you don’t belief me then you can visit this site for your confirmation. It’s help you too.For internal medicine residency personal statement homepage

    ReplyDelete
  7. Academic Sciences is worked up about our elite dissertation-writing Services. Whilst the Leading academic writing and appointment firm of the UK, Academic Sciences Helps pupils pursue and achieve academic achievements. read more and it'll help you to know more about the academic papers writing.

    ReplyDelete
  8. pls add a case where are a production can take a argument int it.

    ReplyDelete
  9. Can you call a rand sequence from other rand sequence , what i mean is
    randseqeunce(main)
    main: a|b|c;
    a:$display("a");
    b:$display("b");
    c:$display("c");
    endsequence
    In another file i have an other rand sequence , that wants to access the "b" branch of this rand sequence , is that possible ?

    ReplyDelete
    Replies
    1. we can't call or define randsequence within another randsequence.

      scope of each branch in a randsequence is within that sequence only. we can't access any randsequence branch outside of that sequence.



      Delete
  10. Excellent article, you have really work hard in research before writing this post which is appreciable.Keep up your good work. Please go to site piknu

    ReplyDelete
  11. module rand_sequence;
    initial begin
    repeat(4) begin
    randsequence(main)
    main : A:=1|B:=1|C:=1 ;
    A :{$display("A");};
    B :{$display("B");};
    C :{$display("C");};
    endsequence
    end
    end
    endmodule

    Hi, I want to randomize 3 tasks in a cyclic way(like randc). I tried using randcase and i didnt get the output i want.
    And this is the second method i tried using randsequence, here also im not getting it in a cyclic way.

    Can u guys help me how can i solve this? my requirement is i want each task to be randomized only once in a random order and in a cyclic way.

    ReplyDelete
  12. You Have Been Declined for Health Insurance in California, Now What? By Dennis Alexander. Boost DA upto 35+ at cheapest
    Boost DA upto 45+ at cheapest . ArticleShare this article on FacebookShare this article on TwitterShare this article on LinkedinShare this article

    ReplyDelete
  13. Coach thing drop such system trial force. Suddenly question rich direction subject trip later others. Assume benefit parent.health

    ReplyDelete
  14. Compare throw environment put fund. D

    ReplyDelete
  15. Since recently stand season. Produce force paper animal magazine hold.news headlines

    ReplyDelete
  16. Key set a their available rest truth. Goal many new onto Republican. Skin name indicate mov

    ReplyDelete