├── .gitattributes ├── .github └── workflows │ └── tg-send.yml ├── LICENSE ├── README.md ├── README_EN.md ├── examples └── demo │ └── demo.ino ├── keywords.txt ├── library.properties └── src └── Random16.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/tg-send.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Telegram Message 3 | on: 4 | release: 5 | types: [published] 6 | jobs: 7 | build: 8 | name: Send Message 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: send telegram message on push 12 | uses: appleboy/telegram-action@master 13 | with: 14 | to: ${{ secrets.TELEGRAM_TO }} 15 | token: ${{ secrets.TELEGRAM_TOKEN }} 16 | disable_web_page_preview: true 17 | message: | 18 | ${{ github.event.repository.name }} v${{ github.event.release.tag_name }} 19 | ${{ github.event.release.body }} 20 | https://github.com/${{ github.repository }} 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Alex 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![latest](https://img.shields.io/github/v/release/GyverLibs/Random16.svg?color=brightgreen)](https://github.com/GyverLibs/Random16/releases/latest/download/Random16.zip) 2 | [![PIO](https://badges.registry.platformio.org/packages/gyverlibs/library/Random16.svg)](https://registry.platformio.org/libraries/gyverlibs/Random16) 3 | [![Foo](https://img.shields.io/badge/Website-AlexGyver.ru-blue.svg?style=flat-square)](https://alexgyver.ru/) 4 | [![Foo](https://img.shields.io/badge/%E2%82%BD%24%E2%82%AC%20%D0%9F%D0%BE%D0%B4%D0%B4%D0%B5%D1%80%D0%B6%D0%B0%D1%82%D1%8C-%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B0-orange.svg?style=flat-square)](https://alexgyver.ru/support_alex/) 5 | [![Foo](https://img.shields.io/badge/README-ENGLISH-blueviolet.svg?style=flat-square)](https://github-com.translate.goog/GyverLibs/Random16?_x_tr_sl=ru&_x_tr_tl=en) 6 | 7 | [![Foo](https://img.shields.io/badge/ПОДПИСАТЬСЯ-НА%20ОБНОВЛЕНИЯ-brightgreen.svg?style=social&logo=telegram&color=blue)](https://t.me/GyverLibs) 8 | 9 | # Random16 10 | Библиотека для быстрой генерации 16 бит случайных чисел 11 | - Алгоритм random 2053 12 | - Получение 16-бит чисел 13 | - Ограничение сверху и снизу 14 | - Класс: возможность создать несколько генераторов 15 | 16 | ### Совместимость 17 | Совместима со всеми Arduino платформами (используются Arduino-функции) 18 | 19 | ## Содержание 20 | - [Установка](#install) 21 | - [Инициализация](#init) 22 | - [Использование](#usage) 23 | - [Пример](#example) 24 | - [Версии](#versions) 25 | - [Баги и обратная связь](#feedback) 26 | 27 | 28 | ## Установка 29 | - Библиотеку можно найти по названию **Random16** и установить через менеджер библиотек в: 30 | - Arduino IDE 31 | - Arduino IDE v2 32 | - PlatformIO 33 | - [Скачать библиотеку](https://github.com/GyverLibs/Random16/archive/refs/heads/main.zip) .zip архивом для ручной установки: 34 | - Распаковать и положить в *C:\Program Files (x86)\Arduino\libraries* (Windows x64) 35 | - Распаковать и положить в *C:\Program Files\Arduino\libraries* (Windows x32) 36 | - Распаковать и положить в *Документы/Arduino/libraries/* 37 | - (Arduino IDE) автоматическая установка из .zip: *Скетч/Подключить библиотеку/Добавить .ZIP библиотеку…* и указать скачанный архив 38 | - Читай более подробную инструкцию по установке библиотек [здесь](https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 39 | ### Обновление 40 | - Рекомендую всегда обновлять библиотеку: в новых версиях исправляются ошибки и баги, а также проводится оптимизация и добавляются новые фичи 41 | - Через менеджер библиотек IDE: найти библиотеку как при установке и нажать "Обновить" 42 | - Вручную: **удалить папку со старой версией**, а затем положить на её место новую. "Замену" делать нельзя: иногда в новых версиях удаляются файлы, которые останутся при замене и могут привести к ошибкам! 43 | 44 | 45 | 46 | ## Инициализация 47 | ```cpp 48 | Random16 rnd; 49 | ``` 50 | 51 | 52 | ## Использование 53 | ```cpp 54 | void setSeed(uint16_t seed); // установить сид 55 | uint16_t get(); // получить случайное число 56 | uint16_t get(uint16_t max); // получить случайное число, ограничить сверху 57 | uint16_t get(uint16_t min, uint16_t max); // получить случайное число, ограничить снизу и сверху 58 | ``` 59 | 60 | 61 | ## Пример 62 | ```cpp 63 | #include 64 | Random16 rnd; 65 | 66 | void setup() { 67 | Serial.begin(9600); 68 | rnd.setSeed(12345); 69 | for (int i = 0; i < 100; i++) { 70 | Serial.println(rnd.get(100, 800)); 71 | } 72 | } 73 | 74 | void loop() { 75 | } 76 | ``` 77 | 78 | 79 | ## Версии 80 | - v1.0 81 | 82 | 83 | ## Баги и обратная связь 84 | При нахождении багов создавайте **Issue**, а лучше сразу пишите на почту [alex@alexgyver.ru](mailto:alex@alexgyver.ru) 85 | Библиотека открыта для доработки и ваших **Pull Request**'ов! 86 | 87 | 88 | При сообщении о багах или некорректной работе библиотеки нужно обязательно указывать: 89 | - Версия библиотеки 90 | - Какой используется МК 91 | - Версия SDK (для ESP) 92 | - Версия Arduino IDE 93 | - Корректно ли работают ли встроенные примеры, в которых используются функции и конструкции, приводящие к багу в вашем коде 94 | - Какой код загружался, какая работа от него ожидалась и как он работает в реальности 95 | - В идеале приложить минимальный код, в котором наблюдается баг. Не полотно из тысячи строк, а минимальный код 96 | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | This is an automatic translation, may be incorrect in some places. See sources and examples! 2 | 3 | # Random16 4 | Library for quick generation 16 bits of random numbers 5 | - Random 2053 algorithm 6 | - Obtaining 16-bit numbers 7 | - restriction from above and below 8 | - Class: the ability to create several generators 9 | 10 | ## compatibility 11 | Compatible with all arduino platforms (used arduino functions) 12 | 13 | ## Content 14 | - [installation] (# Install) 15 | - [initialization] (#init) 16 | - [use] (#usage) 17 | - [Example] (# Example) 18 | - [versions] (#varsions) 19 | - [bugs and feedback] (#fedback) 20 | 21 | 22 | ## Installation 23 | - The library can be found by the name ** random16 ** and installed through the library manager in: 24 | - Arduino ide 25 | - Arduino ide v2 26 | - Platformio 27 | - [download library] (https://github.com/gyverlibs/random16/archive/refs/heads/main.zip). Zip archive for manual installation: 28 | - unpack and put in * C: \ Program Files (X86) \ Arduino \ Libraries * (Windows X64) 29 | - unpack and put in * C: \ Program Files \ Arduino \ Libraries * (Windows X32) 30 | - unpack and put in *documents/arduino/libraries/ * 31 | - (Arduino id) Automatic installation from. Zip: * sketch/connect the library/add .Zip library ... * and specify downloaded archive 32 | - Read more detailed instructions for installing libraries [here] (https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%BD%D0%BE%BE%BE%BED0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA) 33 | ### Update 34 | - I recommend always updating the library: errors and bugs are corrected in the new versions, as well as optimization and new features are added 35 | - through the IDE library manager: find the library how to install and click "update" 36 | - Manually: ** remove the folder with the old version **, and then put a new one in its place.“Replacement” cannot be done: sometimes in new versions, files that remain when replacing are deleted and can lead to errors! 37 | 38 | 39 | 40 | ## initialization 41 | `` `CPP 42 | RANDOM16 RND; 43 | `` ` 44 | 45 | 46 | ## Usage 47 | `` `CPP 48 | VOID setseed (Uint16_T Seeed);// Install SID 49 | uint16_t get ();// get a random number 50 | uint16_t get (uint16_t max);// get a random number, limit from above 51 | uint16_t get (uint16_t min, uint16_t max);// get a random number, limit from below and from above 52 | `` ` 53 | 54 | 55 | ## Example 56 | `` `CPP 57 | #include 58 | RANDOM16 RND; 59 | 60 | VOID setup () { 61 | Serial.Begin (9600); 62 | rnd.Setseed (12345); 63 | for (int i = 0; i <100; i ++) { 64 | Serial.println (rnd.get (100, 800)); 65 | } 66 | } 67 | 68 | VOID loop () { 69 | } 70 | `` ` 71 | 72 | 73 | ## versions 74 | - V1.0 75 | 76 | 77 | ## bugs and feedback 78 | Create ** Issue ** when you find the bugs, and better immediately write to the mail [alex@alexgyver.ru] (mailto: alex@alexgyver.ru) 79 | The library is open for refinement and your ** pull Request ** 'ow! 80 | 81 | 82 | When reporting about bugs or incorrect work of the library, it is necessary to indicate: 83 | - The version of the library 84 | - What is MK used 85 | - SDK version (for ESP) 86 | - version of Arduino ide 87 | - whether the built -in examples work correctly, in which the functions and designs are used, leading to a bug in your code 88 | - what code has been loaded, what work was expected from it and how it works in reality 89 | - Ideally, attach the minimum code in which the bug is observed.Not a canvasof thousands of lines, and minimum code -------------------------------------------------------------------------------- /examples/demo/demo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | Random16 rnd; 3 | 4 | void setup() { 5 | Serial.begin(9600); 6 | rnd.setSeed(12345); 7 | for (int i = 0; i < 100; i++) { 8 | Serial.println(rnd.get(100, 800)); 9 | } 10 | } 11 | 12 | void loop() { 13 | } 14 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Random16 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Random16 KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | setSeed KEYWORD2 15 | get KEYWORD2 16 | 17 | ####################################### 18 | # Constants (LITERAL1) 19 | ####################################### 20 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Random16 2 | version=1.0 3 | author=AlexGyver 4 | maintainer=AlexGyver 5 | sentence=Fast 16 bit random number generator 6 | paragraph=Fast 16 bit random number generator 7 | category=Data Processing 8 | url=https://github.com/GyverLibs/Random16 9 | architectures=* -------------------------------------------------------------------------------- /src/Random16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Библиотека для быстрой генерации 16 бит случайных чисел 3 | Документация: 4 | GitHub: https://github.com/GyverLibs/Random16 5 | Возможности: 6 | - Алгоритм random 2053 7 | - Получение 16-бит чисел 8 | - Ограничение сверху и снизу 9 | - Класс: возможность создать несколько генераторов 10 | 11 | AlexGyver, alex@alexgyver.ru 12 | https://alexgyver.ru/ 13 | MIT License 14 | 15 | Версии: 16 | v1.0 - релиз 17 | */ 18 | 19 | #ifndef Random16_h 20 | #define Random16_h 21 | #include 22 | 23 | class Random16 { 24 | public: 25 | // установить сид 26 | void setSeed(uint16_t seed) { 27 | _seed = seed; 28 | } 29 | 30 | // получить случайное число 31 | uint16_t get() { 32 | _seed = (_seed * 2053ul) + 13849; 33 | return _seed; 34 | } 35 | 36 | // получить случайное число, ограничить сверху 37 | uint16_t get(uint16_t max) { 38 | return ((uint32_t)max * get()) >> 16; 39 | } 40 | 41 | // получить случайное число, ограничить снизу и сверху 42 | uint16_t get(uint16_t min, uint16_t max) { 43 | return (get(max - min) + min); 44 | } 45 | private: 46 | uint16_t _seed; 47 | }; 48 | 49 | #endif 50 | --------------------------------------------------------------------------------