[HELP] RANDOM NUMBER GENERATOR

Ask anything you want to know
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

[HELP] RANDOM NUMBER GENERATOR

Post by shrmaprem0202 »

How to create random number 1000 to 9999
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by francisco »

Hello! Unfortunately there is no direct way to get a random number in a specific range using the {{RANDOM()}} function. However, you can try the following approach:

Code: Select all

{{RANDOM("123456789")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}
What we have here is the function {{RANDOM("1234567890")@CUT(["0", "1"])}} repeated 4 times to obtain a number between 1000 and 9999. A more detailed explanation follows:
  1. RANDOM("1234567890") - Randomizes the string "1234567890", to obtain a random number containing all numerals;
    • The first function does not have 0 in the string to avoid having a range of 0000-9999 instead of the 1000-9999 you want.
  2. CUT(["0", "1"]) - Cuts the string to obtain only the first character of the string, which will be a random number between 0 and 9;
  3. By writing the chain of functions 4 times, we obtain a 4-digit number.
😴
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by shrmaprem0202 »

francisco wrote: Tue Jan 30, 2024 10:38 pm Hello! Unfortunately there is no direct way to get a random number in a specific range using the {{RANDOM()}} function. However, you can try the following approach:

Code: Select all

{{RANDOM("123456789")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}{{RANDOM("1234567890")@CUT(["0", "1"])}}
What we have here is the function {{RANDOM("1234567890")@CUT(["0", "1"])}} repeated 4 times to obtain a number between 1000 and 9999. A more detailed explanation follows:
  1. RANDOM("1234567890") - Randomizes the string "1234567890", to obtain a random number containing all numerals;
    • The first function does not have 0 in the string to avoid having a range of 0000-9999 instead of the 1000-9999 you want.
  2. CUT(["0", "1"]) - Cuts the string to obtain only the first character of the string, which will be a random number between 0 and 9;
  3. By writing the chain of functions 4 times, we obtain a 4-digit number.
What if i need only 1 to 35
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by francisco »

shrmaprem0202 wrote: Wed Jan 31, 2024 4:42 am What if i need only 1 to 35
Hello! Now thanks to the implementation of scripting language support in Wapka (big kudos to Admin!), you can write a Lua script to do this (Wapka Dashboard > Your Site > Your Page > Advanced function > Script):

Code: Select all

-- Initialize the seed to ensure randomness
math.randomseed(os.time())

-- Generate a random number between 1 and 35
local randomNumber = math.random(1, 35)

-- Display the generated number
print(randomNumber)
Random from 1000 to 9999:

Code: Select all

-- Initialize the seed to ensure randomness
math.randomseed(os.time())

-- Generate a random number between 1000 and 9999
local randomNumber = math.random(1000, 9999)

-- Display the generated number
print(randomNumber)
😴
Administrator
Site Admin
Posts: 34
Joined: Tue Mar 07, 2023 7:56 am

Re: [HELP] RANDOM NUMBER GENERATOR

Post by Administrator »

don't use lua script now for production as math library not implemented yet
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by francisco »

Administrator wrote: Wed Jan 31, 2024 4:28 pm don't use lua script now for production as math library not implemented yet
Oh darn, sorry about that.

@shrmaprem0202 I think we will need to wait, cause I can't wrap my head around how to randomize from 1 to 35 using the RANDOM function.
😴
Administrator
Site Admin
Posts: 34
Joined: Tue Mar 07, 2023 7:56 am

Re: [HELP] RANDOM NUMBER GENERATOR

Post by Administrator »

to make random use like this:

Code: Select all

{{RANDOM([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])}}
isn't it easy
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by francisco »

Administrator wrote: Wed Jan 31, 2024 5:18 pm to make random use like this:

Code: Select all

{{RANDOM([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])}}
isn't it easy
Yeah, it's really simple, but I think shrmaprem0202 was wanting something more programmable instead of having to type all the numbers by hand.
I should create some tool to help in this case.
😴
shrmaprem0202
Posts: 38
Joined: Tue Mar 07, 2023 7:13 pm
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by shrmaprem0202 »

francisco wrote: Wed Jan 31, 2024 9:21 pm
Administrator wrote: Wed Jan 31, 2024 5:18 pm to make random use like this:

Code: Select all

{{RANDOM([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35])}}
isn't it easy
Yeah, it's really simple, but I think shrmaprem0202 was wanting something more programmable instead of having to type all the numbers by hand.
I should create some tool to help in this case.


I want to create a random post code there i can use %total% tag in random tag
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: [HELP] RANDOM NUMBER GENERATOR

Post by francisco »

shrmaprem0202 wrote: Wed Jan 31, 2024 4:42 am What if i need only 1 to 35
Okay, so after some thinking I came out with this "thing" to generate random numbers between a given range (just set "start" and "end" - must be positive numbers and end > start):

Code: Select all

{{VALUE(1)@INT@SET(start)@NULL}}
{{VALUE(35)@INT@SET(end)@NULL}}

{{DATE(U)@INT@SET(time)@NULL}}
{{RANDOM("013579")@INT@SET(seed1)@NULL}}
{{RANDOM("02468")@INT@SET(seed2)@NULL}}
{{VAR(time)@DIVIDE@VAR(seed1)@INT@SET(rseed_div)@NULL}}
{{VAR(rseed_div)@MULTIPLY@VAR(seed2)@INT@SET(rseed)@NULL}}
{{VAR(end)@MINUS@VAR(start)@PLUS(1)@SET(range)@NULL}}
{{VAR(rseed)@DIVIDE@VAR(range)@INT@SET(quotient)@NULL}}
{{VAR(quotient)@MULTIPLY@VAR(range)@SET(quotient_divisor)@NULL}}
{{VAR(rseed)@MINUS@VAR(quotient_divisor)@SET(remainder)@NULL}}
{{VAR(remainder)@PLUS@VAR(start)@SET(random_number)@NULL}}


{{VAR(random_number)}}
https://stackoverflow.com/questions/198 ... mod-operat
https://www.w3resource.com/php-exercise ... ise-40.php
😴
Post Reply