Use functions inside constraint block

I am fresh for system Verilog. When I define a random variable(in_m), I set a constraint with the help of my function.


function logic [1023:0]	gcd(input logic unsigned[1023:0] n1, input logic unsigned[1024:0] n2);	// define my function to calculate greatest common divisor;
  while( n1!=n2) begin	
    if(n1>n2) n1 = n1-n2;
    else      n2 = n2-n1;
    end
    gcd = n1;
endfunction: gcd  

rand logic [1023:0] 		in_m; // here declare random variable in_m
bit [1023:0]                    in_n = 1024'h8ff657d86b6b94bc22869c3fe35b11810bc17b450cc81a4d85d9390e6630c893f2d53edc8ffa64d3943d2e3cf065d411234bf3ba8643aa9c8e84293ba7c93ad4f071bb4aec251b84dea2d77faaeb57ffc3ed572b1dd434a83f4884e8dc4c84f7f2bb2f671a0b532e7aa1aad8d7f1e5f345ebe420745db2c334f3aec63beef735;  // just use a large number for example

constraint input_range {gcd(in_m,in_n)==1;} //here is the constraint


But the constraint line is wrong with the following information:

Error-[CNST-ICE] Constraint infeasible constraints error
test/Generator.sv, 56
As the solver has encountered a failure due to an infeasible set of
constraints, the values printed during this solve cycle are invalid.
The solver will preserve original values.
Error-[CNST-CIF] Constraints inconsistency failure
test/Generator.sv, 56
Constraints are inconsistent and cannot be solved.
Please check the inconsistent constraints being printed above and rewrite
them.

Please help me how to fix it. Or could you also tell me how to generate a random number that is co-prime to 2**1024 as well?

Thanks,
Liao

In reply to Liao:

See How to write constraint for generating a continuous mask | Verification Academy