{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b1c35ea3",
   "metadata": {},
   "source": [
    "# 05-05 · Случайные числа\n",
    "\n",
    "Практика к разделу [«Работа со случайными числами»](../../site/chapters/glava-05/05-05-sluchaynye-chisla.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c798541b",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить модуль `random`: random(), randint(), uniform(), choice()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "571889ae",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "959c006a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:19.315261Z",
     "iopub.status.busy": "2026-08-14T20:52:19.315147Z",
     "iopub.status.idle": "2026-08-14T20:52:19.333518Z",
     "shell.execute_reply": "2026-08-14T20:52:19.333010Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "print(random.randint(1, 6))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc49aa2a",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "`randint` включает обе границы — запустите ячейку много раз (или в цикле) и убедитесь, что среди результатов встречаются и 1, и 6."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ad132cf4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:19.334564Z",
     "iopub.status.busy": "2026-08-14T20:52:19.334433Z",
     "iopub.status.idle": "2026-08-14T20:52:19.337260Z",
     "shell.execute_reply": "2026-08-14T20:52:19.336833Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 1, 1, 3, 2, 2, 1, 2, 5, 6, 3, 2, 4, 6, 4, 4, 1, 6, 5, 4]\n",
      "Минимум: 1 Максимум: 6\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "results = [random.randint(1, 6) for _ in range(20)]\n",
    "print(results)\n",
    "print(\"Минимум:\", min(results), \"Максимум:\", max(results))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2bc41da",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "Выберите случайный элемент из своего списка вариантов."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0aeb2980",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:19.338239Z",
     "iopub.status.busy": "2026-08-14T20:52:19.338126Z",
     "iopub.status.idle": "2026-08-14T20:52:19.340266Z",
     "shell.execute_reply": "2026-08-14T20:52:19.339861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "камень\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "variants = [\"камень\", \"ножницы\", \"бумага\"]\n",
    "print(random.choice(variants))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e8d86ed",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Симулируйте бросок двух кубиков и выведите сумму очков."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2d7e41af",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:19.341281Z",
     "iopub.status.busy": "2026-08-14T20:52:19.341094Z",
     "iopub.status.idle": "2026-08-14T20:52:19.344226Z",
     "shell.execute_reply": "2026-08-14T20:52:19.343757Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 + 2 = 6\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "dice1 = random.randint(1, 6)\n",
    "dice2 = random.randint(1, 6)\n",
    "print(dice1, \"+\", dice2, \"=\", dice1 + dice2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e66b854",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Симулируйте 1000 бросков одного кубика и посчитайте, сколько раз выпала каждая грань — числа должны быть примерно равны."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a43791cf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:19.345260Z",
     "iopub.status.busy": "2026-08-14T20:52:19.345140Z",
     "iopub.status.idle": "2026-08-14T20:52:19.347853Z",
     "shell.execute_reply": "2026-08-14T20:52:19.347408Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 156, 2: 173, 3: 174, 4: 158, 5: 178, 6: 161}\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "counts = {n: 0 for n in range(1, 7)}\n",
    "for _ in range(1000):\n",
    "    roll = random.randint(1, 6)\n",
    "    counts[roll] += 1\n",
    "\n",
    "print(counts)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
