How can integer array use stream function

I have a 10 digit random number and want to check if it’s dividable by 9 (other restrictions are upper three digits cannot consecutive in increasing order (0-1-2, 8-9-0 both not ok)).I’m thinking declare a packed array, and use constraint as {array} >>} % 9 != 0 to do. But don’t know how to declare a packed integer array.

In reply to aaaaaa:

What do you mean by a digit? Do you mean an array of 4-bit binary coded decimal digits?

Show some example values.

In reply to dave_59:
Hey. I mean for it is like 0123456789. 10 digits. I want to rand a number like this.

In reply to aaaaaa:
What do you mean by a digit? Do you mean an array of 4-bit binary coded decimal digits?
Show some example values.

In reply to aaaaaa:

Are those decimal digits or hexadecimal digits?

In reply to dave_59:
decimal. So always 0-9.

In reply to aaaaaa:
Are those decimal digits or hexadecimal digits?

In reply to aaaaaa:

module abc;
  initial begin
    //option-1 : if you want to check the 10-digit integer value is multiple of 9
    int array = 0123456789;
    $display(array % 9);

    //option-2 : if you want to check multiple of 9, reducing one digit every time
    array = 0123456789;
    while(array != 0)begin
      $display(array, array % 9 );
	   array = array/10;
    end
    
    //option-3 : if you want to check the multiple of 9, for each of the digit in 10-digit value
    array = 0123456789;
    while(array != 0)begin
      $display(array, (array%10) % 9);
	   array = array/10;
    end
  end
endmodule

may be you are looking for one of the these three options?

In reply to yourcheers:

Since this seems to be an interview question that you both have failed, let me ask a few questions as hints.

  1. How many binary bits do you need to store a 10-digit decimal number
  2. How do you convert a binary number to decimal digits?

In reply to yourcheers:
Hi. I think I may declare the question more in details. Since there are more restrictions. For example, the upper three digits cannot be consecutive. That’s why I think I need to choose array.

In reply to aaaaaa:

module abc;
initial begin
//option-1 : if you want to check the 10-digit integer value is multiple of 9
int array = 0123456789;
$display(array % 9);
//option-2 : if you want to check multiple of 9, reducing one digit every time
array = 0123456789;
while(array != 0)begin
$display(array, array % 9 );
array = array/10;
end
//option-3 : if you want to check the multiple of 9, for each of the digit in 10-digit value
array = 0123456789;
while(array != 0)begin
$display(array, (array%10) % 9);
array = array/10;
end
end
endmodule

may be you are looking for one of the these three options?

In reply to dave_59:

How many binary bits do you need to store a 10-digit decimal number

min 30, max 34
How do you convert a binary number to decimal digits?
multiply each binary digit with base & sum.

In reply to yourcheers:

class A;
  rand bit [33:0] number; // minimum 34 bits needed to hold 10 decimal digits
  rand bit [3:0] digits[9:0];
  constraint n {
    number % 9 == 0;           // must be divisible by 9
    number < 34'd1_0000000000; // decimal range
    foreach(digits[i]) // binary coded decimal BCD conversion
      digits[i] < 10;
    digits.sum(digit) with (digit * 34'd10**digit.index) == number;
  }
endclass

module top;
  A a=new;
  initial repeat (10) begin
    assert(a.randomize());
    $display("%10d %0p", a.number, a.digits);
  end
endmodule