rand() ã®åé¡ç¹ ããã¾ã§åºã使ç¨ããã¦ãã rand() ã«ããä¹±æ°çæã«ã¯ä»¥ä¸ã®åé¡ç¹ãããã çæãããç¯å²ã [0, 32767] ã¨çã rand() % N ã¯ä¸æ§ã§ã¯ç¡ã å¨æããã¾ãé·ããªã ä¹±æ°çæã¢ã«ã´ãªãºã ãåºå®ï¼é常ã¯ç·å½¢ååæ³ï¼ æ£è¦åå¸ãªã©ãä¸æ§ã§ãªãä¹±æ°çæãé¢å rand() ã§çæãããå¤ã®ç¯å²ã¯ [0, 32767] ã¨çãã15ããããããªãã (rand() << 15) + rand() ã¨ããã°ã30ãããä¹±æ°ã«ãããã¨ã¯å¯è½ã ããã¹ãã¼ãã§ã¯ãªããã çæã¢ã«ã´ãªãºã ã®é¢ä¿ã§ãä¹±æ°ã«åããåºãå ´åãããã é常ãä¹±æ°ã¨ãã¦æ¬²ããã®ã¯ [0, N) ç¯å²ã®å¤ã§ãããã¨ãå¤ãããã®å ´å㯠rand() % N ã¨ãããã¨ãä¸è¬çã ã ãããããã®ããã«ãã¦çæããä¹±æ°ã¯ä¸æ§ã§ãªãåãããããç¹ã« N ã大ããæã«ãã®ç¾è±¡ãé¡èã«ãªãã ä¾ãã°
{{#tags}}- {{label}}
{{/tags}}