vis[x] = 1是什么意思

int TBLCreate(MNG* pMng, int nCnt) 
{
  memset(vis, 0, sizeof(vis)); //防止随机值重复
  if (!pMng)
    return -1;
  pMng->nNodeCnt = nCnt;
  LTBL* p = (LTBL*)malloc(sizeof(LTBL)); //创建头节点
  if (!p)
    return -1;
  int x = 0;
  x = rand() % 1000;
  vis[x] = 1;
  p->nKey = x;
  p->pPre = NULL;
  p->pNxt = NULL;
  pMng->pHead = p;

  for (int i = 1; i < nCnt; ++i) 
  {
    LTBL* temp = (LTBL*)malloc(sizeof(LTBL));
    if (!temp)
      return -1;
    while (1)//随机值防止重复
    { 
      x = rand() % 1000;
      if (!vis[x]) 
      {
        vis[x] = 1;
        break;
      }
    }
    temp->nKey = x;
    temp->pNxt = NULL;
    temp->pPre = p;//新节点前驱指向当前节点
    p->pNxt = temp;//当前节点的后继为新节点
    p = p->pNxt;//当前节点后移
  }
  return 0;
}

memset(vis, 0, sizeof(vis)); //防止随机值重复
x = rand() % 1000; 取到随机数x之后,令 vis[x] = 1; 它实际上就是一个flag,表示x这个随机数已经被用过了,所以用vis[x] = 1 标记一下,
while (1)//随机值防止重复
{
x = rand() % 1000;
if (!vis[x])
{
vis[x] = 1;
break;
}
}
所以这里就是如果 vis[x] = 1的话,说明此随机数已存在,那么继续循环取下一个不存在的随机数,如果取到了,标记为1,然后break退出。

    ------希望采纳!!