Generate pattern using constraints

Generate pattern using constraints where
R-red with range [0:15]
G-green with range [16:30]
B-blue with range [31:50]
Pattern is RGBBGR?

In reply to patil shweta:

I guess R, G, and B representing an enumertaion type. And R, G, and B are representing exactly 1 value, respectively. The range might indicate the width of the enumeration type.

In reply to patil shweta:

Hello patil shweta!

Here is the code I’ve tried till displaying the colors and their respective ranges twice.

//Generate pattern RGBBGR

class packet;

	rand enum {R,G,B} color;
	
	rand int range;
	
	constraint c_RGB {
					
			if (range inside {[0:15]}) {
					
						color == R;
	
						   }
												
			if (range inside {[16:30]}) {
					
						color == G;
												
						     }
												
		        if (range inside {[31:50]}) {
					
					        color == B;
												
						    }
					
			}
					
	constraint c_range {range inside {[0:50]};}

        constraint c_pattern_dist {range dist {[0:15]:/2, [16:30]:/2, [31:50]:/2};}
	
endclass: packet


module pattern;
	
	initial 
	
		begin
		
			packet pkt = new;
			
			$display("\nThe pattern is as follows:");
			
			repeat (6)
			
				begin
					
					pkt.randomize;
					
					$display("\n%0s \t%0d",pkt.color.name,pkt.range);
					
				end
				
		end
												
endmodule: pattern

You can use post-randomization for the pattern.

In reply to patil shweta:

I don’t think anyone understood your question. Is “range” a value or range of bits in a larger vector? Can you give declare the variables you want randomized and give some example values that would meet the constraints you are looking for?

In reply to Shashank Gurijala:

if i change the pattern to display ,these code will be same?

In reply to patil shweta:

Sorry, I didn’t get you.

But patil shweta, I only coded till you obtain 2 R’s, G’s and B’s respectively and not in the order you asked for which is RGBBGR.

In reply to Shashank Gurijala:

If I given pattern like RGBBRGB,THESE code will be same for that pattern

In reply to patil shweta:

You haven’t explained your problem with the necessary details. Can you show declarations the variables you want randomized and give some example values that would meet the constraints you are looking for?