{"id":334,"date":"2025-10-18T07:13:14","date_gmt":"2025-10-18T07:13:14","guid":{"rendered":"https:\/\/informatika.tbg.hu\/?page_id=334"},"modified":"2025-10-18T08:06:33","modified_gmt":"2025-10-18T08:06:33","slug":"veletlen-szamok","status":"publish","type":"page","link":"https:\/\/informatika.tbg.hu\/index.php\/veletlen-szamok\/","title":{"rendered":"V\u00e9letlen sz\u00e1mok"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ahhoz, hogy sz\u00e1mokat tudjunk el\u0151\u00e1ll\u00edtani v\u00e9letlenszer\u0171en, kell defini\u00e1lnunk egy v\u00e9letlensz\u00e1m gener\u00e1tort. Ez a Random oszt\u00e1ly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Random gener\u00e1tor=new Random();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ha ez k\u00e9sz, akkor m\u00e1r tudunk \u00e1ltala sz\u00e1mokat k\u00e9sz\u00edteni. Ak\u00e1rmennyit, ak\u00e1rmilyet. <strong>\u00dajabb sz\u00e1mokn\u00e1l nem kell \u00fajabb gener\u00e1tort alkalmazni<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Eg\u00e9sz sz\u00e1mok als\u00f3 \u00e9s fels\u0151hat\u00e1r megad\u00e1s\u00e1val. Az als\u00f3 hat\u00e1r m\u00e9g lehets\u00e9ges \u00e9rt\u00e9k, a fels\u0151 m\u00e1r nem.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Szeretn\u00e9nk egy sz\u00e1mot k\u00e9sz\u00edteni 1 \u00e9s sz\u00e1z k\u00f6z\u00f6tt. Akkor a k\u00f3dom:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Random gener\u00e1tor=new Random();\nint sz\u00e1m=gener\u00e1tor.Next(1,101);<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"90\" src=\"https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.Next_.png\" alt=\"Random.Next\" class=\"wp-image-337\" srcset=\"https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.Next_.png 784w, https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.Next_-300x34.png 300w, https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.Next_-768x88.png 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><figcaption class=\"wp-element-caption\">Eg\u00e9sz sz\u00e1m gener\u00e1l\u00e1sa als\u00f3 \u00e9s fels\u0151 hat\u00e1rok megad\u00e1s\u00e1val<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Mi\u00e9rt \u00edrtam 1-et \u00e9s 101-et a z\u00e1r\u00f3jelbe? Mert az 1 a legkisebb m\u00e9g lehets\u00e9ges \u00e9rt\u00e9k, a legnagyobb pedig 101-n\u00e9l kisebb eg\u00e9sz sz\u00e1m (100 :))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mi t\u00f6rt\u00e9nik, ha nem \u00edrok hat\u00e1rokat? Milyen sz\u00e1mokat k\u00e9sz\u00edt a C#, ha ezt \u00edrom?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Random gener\u00e1tor=new Random();\nint sz\u00e1m=gener\u00e1tor.Next();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ilyenkor 0 \u00e9s int.MaxValue k\u00f6z\u00e9 es\u0151 eg\u00e9sz sz\u00e1mot gener\u00e1l.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00c9s ha csak egy param\u00e9tere van? P\u00e9ld\u00e1ul gener\u00e1tor.Next(101) ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ilyenkor 0 \u00e9s 100 k\u00f6z\u00e9 es\u0151 sz\u00e1mokat gener\u00e1l, a sz\u00e9ls\u0151\u00e9rt\u00e9ket bele\u00e9rte.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">T\u00f6rt sz\u00e1mok. 0 \u00e9s 1 k\u00f6z\u00e9 es\u0151 t\u00f6rt sz\u00e1mok. A 0 lehets\u00e9ges, az 1 m\u00e1r nem.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Van lehet\u0151s\u00e9gem t\u00f6rt sz\u00e1mok el\u0151\u00e1ll\u00edt\u00e1s\u00e1ra is. Ilyenkor <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Random gener\u00e1tor=new Random();\ndouble sz\u00e1m=gener\u00e1tor.NextDouble();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">k\u00f3dsort alkalmazom. Ez a sz\u00e1m v\u00e1ltoz\u00f3 &#8222;dob&#8221; egy 0 \u00e9s 1 k\u00f6z\u00e9 es\u0151 sz\u00e1mot \u00fagy, hogy az 1 m\u00e1r nem nem el\u00e9rhet\u0151.<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"118\" src=\"https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.NextDouble.png\" alt=\"Random.NextDouble\" class=\"wp-image-338\" srcset=\"https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.NextDouble.png 776w, https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.NextDouble-300x46.png 300w, https:\/\/informatika.tbg.hu\/wp-content\/uploads\/2025\/10\/Random.NextDouble-768x117.png 768w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><figcaption class=\"wp-element-caption\">T\u00f6rt sz\u00e1m gener\u00e1l\u00e1sa 0 \u00e9s 1 k\u00f6z\u00f6tt<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Ahhoz, hogy sz\u00e1mokat tudjunk el\u0151\u00e1ll\u00edtani v\u00e9letlenszer\u0171en, kell defini\u00e1lnunk egy v\u00e9letlensz\u00e1m gener\u00e1tort. Ez a Random oszt\u00e1ly. Ha ez k\u00e9sz, akkor m\u00e1r tudunk \u00e1ltala sz\u00e1mokat k\u00e9sz\u00edteni. Ak\u00e1rmennyit, ak\u00e1rmilyet. \u00dajabb sz\u00e1mokn\u00e1l nem kell \u00fajabb gener\u00e1tort alkalmazni. Eg\u00e9sz sz\u00e1mok als\u00f3 \u00e9s fels\u0151hat\u00e1r megad\u00e1s\u00e1val. Az als\u00f3 hat\u00e1r m\u00e9g lehets\u00e9ges \u00e9rt\u00e9k, a fels\u0151 m\u00e1r nem. Szeretn\u00e9nk egy sz\u00e1mot k\u00e9sz\u00edteni 1 \u00e9s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-334","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/pages\/334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":3,"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/pages\/334\/revisions"}],"predecessor-version":[{"id":341,"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/pages\/334\/revisions\/341"}],"wp:attachment":[{"href":"https:\/\/informatika.tbg.hu\/index.php\/wp-json\/wp\/v2\/media?parent=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}