<commit_before>"""
Support for showing random numbers.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.random/
"""
import asyncio
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (CONF_NAME, CONF_MINIMUM, CONF_MAXIMUM)
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Random Sensor'
DEFAULT_MIN = 0
DEFAULT_MAX = 20

ICON = 'mdi:hanger'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_MAXIMUM, default=DEFAULT_MAX): cv.positive_int,
    vol.Optional(CONF_MINIMUM, default=DEFAULT_MIN): cv.positive_int,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Setup the Random number sensor."""
    name = config.get(CONF_NAME)
    minimum = config.get(CONF_MINIMUM)
    maximum = config.get(CONF_MAXIMUM)

    hass.loop.create_task(async_add_devices(
        [RandomSensor(name, minimum, maximum)], True))
    return True


class RandomSensor(Entity):
    """Representation of a Random number sensor."""

    def __init__(self, name, minimum, maximum):
        """Initialize the sensor."""
        self._name = name
        self._minimum = minimum
        self._maximum = maximum
        self._state = None

    @property
    def name(self):
        """Return the name of the device."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def icon(self):
        """Icon to use in the frontend, if any."""
        return ICON

    @asyncio.coroutine
    def async_update(self):
        """Get a new number and updates the states."""
        from random import randrange
        self._state = randrange(self._minimum, self._maximum)<commit_msg>Change behavior to be more natural and fix test (#4150)<commit_after>"""
Support for showing random numbers.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.random/
"""
import asyncio
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (CONF_NAME, CONF_MINIMUM, CONF_MAXIMUM)
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Random Sensor'
DEFAULT_MIN = 0
DEFAULT_MAX = 20

ICON = 'mdi:hanger'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_MAXIMUM, default=DEFAULT_MAX): cv.positive_int,
    vol.Optional(CONF_MINIMUM, default=DEFAULT_MIN): cv.positive_int,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Setup the Random number sensor."""
    name = config.get(CONF_NAME)
    minimum = config.get(CONF_MINIMUM)
    maximum = config.get(CONF_MAXIMUM)

    hass.loop.create_task(async_add_devices(
        [RandomSensor(name, minimum, maximum)], True))
    return True


class RandomSensor(Entity):
    """Representation of a Random number sensor."""

    def __init__(self, name, minimum, maximum):
        """Initialize the sensor."""
        self._name = name
        self._minimum = minimum
        self._maximum = maximum
        self._state = None

    @property
    def name(self):
        """Return the name of the device."""
        return self._name

    @property
    def state(self):
        """Return the state of the device."""
        return self._state

    @property
    def icon(self):
        """Icon to use in the frontend, if any."""
        return ICON

    @asyncio.coroutine
    def async_update(self):
        """Get a new number and updates the states."""
        from random import randrange
        self._state = randrange(self._minimum, self._maximum + 1)
{'fraction_non_alphanumeric': 0.09816247582205029, 'fraction_numerical': 0.0026595744680851063, 'mean_word_length': 3.606904231625835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1677605', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1214, 'n_words': 345}