Questions tagged [random]

The focus of this tag is on inquiries related to random numbers and the mechanisms used to generate them, including both pseudo-random and genuinely random processes.

Perform a task X number of times every X hour using Python and Django

I am looking to create a program that can perform a task a specified number of times within a given time frame. For example, I want the task to be done 10 times every hour, or 10 times every day, or 3 times every day. I want this to be customizable by prov ...

What is the best way to retrieve a random selection of strings from a given input?

import random def generate_random_strings(characters): return [random.choice(characters) for _ in range(4)] if __name__ == '__main__': characters = 'ygobpr' print(generate_random_strings(characters)) What is the best way to obtain a list of 4 ...

The system encountered an issue: "Property 'add' is not defined and cannot be read."

I'm facing a dilemma with my exercise. Despite the numerous inquiries regarding this problem, I haven't been able to find a solution. I am hopeful that you can provide some assistance! Below is the code snippet in question: let myDivs = document.querySe ...

applying different styles to various elements

As a newcomer to the world of jQuery, I am attempting to achieve the following goal: I have several instances of a div, and for each instance, I randomly assign a class from a predefined list in order to modify certain attributes. While this process is su ...

Using Python to generate 'n' random integer figures within two specified values that add up to a specific number

Looking to generate a set of n random integers between two specific values (min, max) with the constraint that their sum equals a given number m. It seems like existing solutions on StackOverflow do not precisely solve this issue, as they don't invol ...

Is there a way to simulate pressing arrow keys randomly using Selenium in Python?

My current project involves creating a program that can play the game 2048 by randomly choosing arrow keys. I attempted the following code snippet: moves = [htmlElem.send_keys(Keys.UP),htmlElem.send_keys(Keys.RIGHT),htmlElem.send_keys(Keys.DOWN),htmlEle ...

What is the best way to program a function that can extract random lines from a text file and save them in a variable?

Can someone enlighten me on how to create a function that reads from a txt file and saves random lines into a variable? This function needs to be executed multiple times within a foreach loop, and the language used is PHP. I'm still new to coding, so ...

Utilize Javascript to create a function that organizes numbers in ascending order

Is there a way to modify this code so that the flip clock digits appear in ascending order rather than randomly? $( '.count' ).flip( Math.floor( Math.random() * 10 ) ); setInterval(function(){ $( '.count' ).flip( Math.floor( Math.rand ...

Choose a file at random from the folder, assigning probabilities based on the file names

When it comes to font files, they often have names like FontName-type.extension. All these files are stored in a single folder and I currently have this function: function random_font($dir = 'fonts') { $fonts = glob($dir . '/*'); ...

Learn how to shuffle the filenames of all the files within a single folder using Python

I am looking to randomize the names of all the files in a folder by swapping filenames with other files, ultimately achieving this for over 100 files. What would be the most efficient method to accomplish this goal? ...

Is it recommended to utilize either a single or multiple instances of Python's secrets.SystemRandom() class?

When it comes to generating random numbers securely, I stumbled upon the secrets module which seems to be the go-to solution. However, I have a question - should I create one or multiple instances of the secrets.SystemRandom class for generating 17 random ...

What is the best way to utilize React in order to assign a random background according to each element's id for numerous elements?

Currently, I have integrated a Swiper component into my React application. The Swiper consists of n slides, with each slide requiring a set of m images to be randomly selected as the background upon loading. Prior to transitioning to React, I had devised ...

Generating random user IDs and populating them into a text box using Selenium and Java

For the application I'm working on, I have to create new users frequently. I need a code snippet that can generate usernames using regular expressions. For example, "Alen001", "Alen002", "Alen003" and so forth. driver.findElement(By.id("userId")).sen ...

various locations within a hexagonal zone or figure

In my project, I am working with a simple hexagonal grid. My goal is to select a group of hexagons and fill them with random points. Here is the step-by-step process of generating these points: I start by selecting hexagons using a list of hex coordinat ...

Avoid selecting random 8-character words

I have implemented the random module in a project, despite not being a programmer. My task involves creating a script that can generate a randomized database from an existing one. Specifically, I need the script to pick random words from a column in the "w ...

Can you explain how to use a toggle switch to make a select dropdown select a random option?

Currently, I am in the process of setting up a page for a character generator. Users will have the option to randomize traits or input their own. The interface includes toggle switches for the "choice vs random" options for each trait category, as well as ...

Unique content on a web page when it is loaded with HTML

Is there a way to dynamically load various content (such as <img> and <a>) into divs every time a page is loaded? I've seen websites with dynamic or rotating banners that display different content either at set intervals or when the page ...

random.random function was called with an unexpected argument (1 given)

Having trouble understanding how random.random selects from a list of functions in cmd_advice (assuming that's the correct method)? My debugger is throwing a TypeError: random() takes no arguments (1 given). I'm still learning, so please excuse any mistak ...

Random variable without repetition in SASS

I have a unique project where I am tasked with incorporating a list of 5 specific colors into 10 different div elements. The challenge is that each color must be used twice and in a completely random order without any repetition of colors. Although utilizi ...

Error: invalid range specified in np.random.randint [New Error Type]

import glob import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import numpy as np dataset_paths = glob.glob("dataset_characters/**/*.jpg") cols=3 rows=3 fig = plt.figure(figsize=(10,8)) plt.rcParams.update({"font.size&q ...

Is it possible to randomly generate an arithmetic operator and ensure its validity?

Attempting to generate a list of arithmetic operations randomly, taking into account the operators. The goal is to introduce randomness by adding parentheses as an operator on both sides. For example:- (2) + (51) = However, when I try to implement this in ...

Unpredictable selection of elements displayed as links

As someone who is relatively new to PHP and HTML, I am working on a website that features a product of the week. However, I have hit a roadblock in implementing my idea. My concept involves creating an array with various products and using array_rand to s ...

Utilize the useEffect hook in Next.js to shuffle an array randomly

Every time the page is loaded, I want to randomize an array. I am working with Nextjs and facing the issue of client-server mismatch. I have been advised to use a useEffect hook to solve this problem, but I seem to be doing it incorrectly. Can someone plea ...

The random number generator in TypeScript not functioning as expected

I have a simple question that I can't seem to find the answer to because I struggle with math. I have a formula for generating a random number. numRandomed: any; constructor(public navCtrl: NavController, public navParams: NavParams) { } public ...

Shuffle a Document Fragment in a random order before adding it to the DOM using JavaScript

My JavaScript code is generating a text area and button dynamically. I have successfully implemented it so that when a value is entered into the text area and the button is clicked, a random number of SPAN tags are created. Each character from the input va ...

Python Number Guessing Challenge

As a newcomer to Python programming, I have been delving into version 2.7.4 and recently worked on creating a number guessing game. Below is the code snippet for my current progress: import random name = raw_input("Hi there! What\'s your name?&b ...

What is the best way to create random integers using JavaScript?

Is there a way to create a function called drawSomething(x, y, color, boolean) that will generate random integers for the position of x and y on the canvas, randomly select a color from red, yellow, or blue, and randomly assign true or false to the boole ...

What is the way to obtain a random element in Java code?

I need to select a random element from my Java code. Let's say I have 4 elements in my code and I want to start running the program from the second element, then switch to another element on each subsequent run. How can I achieve this? first eleme ...

Steps for generating random numbers from a set of given numbers

I am faced with a scenario where I need to generate random numbers based on a given set of numbers. For instance, if I have an array num=[23,56,12,22], I would like to obtain a random number from this array. ...

The For loop with varying lengths that exclusively produces small numbers

I'm currently using a for loop that iterates a random number of times: for(var i = 0; i<Math.floor(Math.random()*100); i++){ var num = i } This method seems to be skewed towards producing lower numbers. After running it multiple times, the &apo ...

Alert-Enabled Random Number Generation Tool

I'm struggling to create a program that randomly generates a number between 1 and 20. If the number is less than 10, it should display "fail," and if it's greater than 10, it should display "success." I can't seem to figure out where I went wrong. Can so ...

Can you please explain the specific function of random.random?

random.shuffle(lst_shuffle, random.random) I am unsure about the optional argument in the code snippet above. Can someone please explain its purpose? This piece of code is found in the documentation. random.random()ΒΆ Returns the next random floating ...

What is the best way to generate a Python list of size L filled with random numbers between 1 and N?

If I use the getList(10,6) function, will the list contain 10 numbers ranging from 1 to 6 with possible repeats? For instance, [1,4,2,6,3,8,5,5,2,1] Should I simply generate random numbers using randrange and keep appending them, or is there a more effici ...

Python implementation of Weibull distribution-based randomization

I am looking to utilize the Weibull function in order to create random numbers that fall within a specific range. Although I am aware of the scipy function weibull_min.rvs(k, loc=0, scale=lam, size=n, random_state=5), which generates a specified number of ...

Having trouble retrieving a random document from a MongoDB collection?

I'm currently developing a word game and facing the challenge of displaying a random wordpair from my collection on page load. Utilizing Express, I've modified my code based on a helpful tutorial. With a successful GET request rendering my page correctly, ...

Generate unique IDs in Laravel 6 or higher that consist only of numbers and also incorporate additional logic

Currently, I am generating a unique ID using the time() function which results in about 10 digits. However, I need to store an 18-digit number. To achieve this, I plan to generate random numbers of 3 digits, 3 digits, and 2 digits respectively. I have so ...

Creating a unique, random output while maintaining a log of previous results

While working on a recent project, I found myself in need of a custom Javascript function that could generate random numbers within a specified range without any repetitions until all possibilities were exhausted. Since such a function didn't already ...

execute php function when form is submitted

Hello, I am attempting to create a code using this PHP function: <?php function generateRandomString($length = 6) { return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)))) ...

Guide: Generating a Random Number with Prefix using Python

Can you help me create a list of all potential numbers in the given prefix? import random prefix = "05" print prefix + #List of Potential Numbers Goes Here ...

Problem with escaping special characters in random string HTML

As I was in the process of creating a JavaScript tool to generate random strings, with or without special characters, I stumbled upon an inspiring snippet that caught my attention: (): function randStr(len) { let s = ''; while (len--) s += String.fr ...

React app experiencing freezing due to custom asynchronous function utilisation

I am currently facing an issue with my personal project where the application freezes under certain circumstances. The initial load works fine, but when I make changes to the code causing React to re-render, the app just freezes. It seems to be related to ...