ΥڡϤƤʥ֥åޡɲΥڡޤϤƤʥ֥åޡ Υڡlivedoor åפɲΥڡޤlivedoor å

  • "pseudo-randam"
  • ͭ¾ֿη׻Ȥä¤˺ƸΤ뵼ɬŪˤʤ롣
    • ׻ͭ¾֤ʤȡĤϲȤƱ֤ˤʤ롣θƱˤʤ롣Ĥޤꡢ¸ߤ롣
  • ׻ʳΤǤϤޤΤʤ餷ŹʬǤΤ롣
    • Ϳơ¿༰֤ǤϤοȿζ̤դʤСȸƤФ롣

ɬ

  • ߥ졼
    • Ʊ¸򷫤֤˺Ƹɬס
  • Ź浻

ؿͤäƤȤˡ礭

ؿνͤǤʣε­ꡢݤƤϤޤ󡣤ʤʤФͤϳΤ˾ͤ礭ͤˤʤ뤬ʬۤͤǤϤʤʤäƤޤǤϤʤʤ롣 㤨СäȤޤϰεȤѤǤ롣2󥵥򿶤äơͤ­Ƥޤȡ212ϰϤοͤˤʤ롣ʬۤϰͤǤϤʤʤ롣7ֽФ䤹212ϰֽФˤǤ롣ޤݤѤȡ136ϰϤοͤΤ11ʤɤФ˽Фʤäơ­ΤȤǤݤΤȤǤʬۤˤʤäƤʤΤǤ롣

㤨СCrand()0ʾ32767̤ε֤rand()Ȥä32767ʾεͤꤿϡΤ褦ˤ롣r1,r2rand()νͤȤ롣

r3r1 ( + 1) + r2

ĤޤꡢΤ褦ˤФ褤

int r = rand() * 32768 + rand();

01073741823ε뤳ȤǤ롣RNAD_MAX32767(=111 1111 1111 11112=0x7fff)ǡ15ӥåʬͭȤǤСΤ褦ˤƤ嵭Ʊ̤֤̤ͤ30ӥåȤˤʤޤ

int val = (rand() << 15) | rand();

rand()٤ޤ褯ʤΤǡr1r2˴Ϣ뤿ᡢr3ϰʬۤǤϤʤФ꤬ФƤޤʤ⤷r1,r2ΩǤСr3ϰͤʵˤʤ롣