{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3dfa74b0",
   "metadata": {},
   "source": [
    "# 04-20 · random vs secrets\n",
    "\n",
    "Практика к разделу [«random и secrets»](../../site/chapters/glava-04/04-20-random-i-secrets.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c930c521",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить random для игр и понять, когда нужен secrets."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "856517a9",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8e77565a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:02.548292Z",
     "iopub.status.busy": "2026-08-16T10:04:02.548133Z",
     "iopub.status.idle": "2026-08-16T10:04:02.569655Z",
     "shell.execute_reply": "2026-08-16T10:04:02.569270Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "random.seed(42)\n",
    "print(random.randint(1, 6))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d69f43a",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Выберите случайный элемент из списка."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6a110ff0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:02.570913Z",
     "iopub.status.busy": "2026-08-16T10:04:02.570804Z",
     "iopub.status.idle": "2026-08-16T10:04:02.573090Z",
     "shell.execute_reply": "2026-08-16T10:04:02.572686Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "орёл\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "random.seed(1)\n",
    "print(random.choice([\"орёл\", \"решка\"]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14cdb603",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Создайте безопасный токен через secrets.token_hex()."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "83410074",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:04:02.573980Z",
     "iopub.status.busy": "2026-08-16T10:04:02.573808Z",
     "iopub.status.idle": "2026-08-16T10:04:02.576137Z",
     "shell.execute_reply": "2026-08-16T10:04:02.575712Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n"
     ]
    }
   ],
   "source": [
    "import secrets\n",
    "token = secrets.token_hex(8)\n",
    "print(len(token))"
   ]
  }
 ],
 "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
}
