Stan Function not found!

I am trying to use Stan to generate some data and Z is supposed to be an indicator matrix. I am receiving the following error message “No matches for : discrete_range_rng(int, int)
Function discrete_range_rng not found.”

data {
  int<lower = 1> N;               // Number of observations.
  int<lower = 1> q;               // Number of responses.
   int<lower = 1> m;               // Number of random effects.
  int<lower = 1> I;               // Number of observation-level covariates.
  int<lower = 1> qN;               // Number of total observations.
  int<lower = 1> qm;               // Number of total random effects.

generated quantities {
  int j=1;
   int<lower = 1> ind;
    int<lower = 1> ind2;
matrix[qN,qm] Z;
while(j <= qN-1){
  ind= discrete_range_rng(1,m)
  ind2= discrete_range_rng(1,m)
  Z[j,ind]= 1
  Z[j+1,ind2]= 1
  Z[j+1,ind]= 0

This is my R code which do what I want I want to use stan generate my data
Z ← matrix(0,responsestudents,teachersresponse)

while(j <= responsestudents-1){
ind ← sample(teachers
ind2 ← sample(teachers*response,1,rep=F)
Z[j,ind] ← 1
Z[j+1,ind2] ← 1
Z[j+1,ind] ← 0


Hi and sorry about the late response.

If you still need help can you post your version of R and rstan?

This is because the discrete_range_rng function isn’t available in the version of Stan currently in rstan.

You’ll need to either use cmdstanr or the preview version of rstan:

remove.packages(c("StanHeaders", "rstan"))
install.packages("StanHeaders", repos = c("", getOption("repos")))
install.packages("rstan", repos = c("", getOption("repos")))

Sorry for the late reply Thanks very it works