Math functions (ceiling, floor, random)
4332
Views
31
Comments
New
Builtin & User functions

The platform lack 3 commonly used math functions:


- ceiling(decimal)

- floor(decimal)

- random(n, m): generates a number between n and m


It would be usefull to have them built-in.

I second this recommendation

I agree, these are basic math functions and should therefore be in Outsystems.

2016-04-21 18-13-58
Nuno Rolo
 
MVP

Five years past and still no sign of this. How hard can it be?

Yes, My vote for you. This is very useful.

I found a workaround for floor and ceil. Though it will only round on full numbers.

Ceil = Trunc(Value + 0.99)
Floor = Trunc(Value)

7 years and counting.. Please implement this!

sure would be nice... 

Merged this idea with 'Can we have an option to generate random number between defined range?' (created on 01 Aug 2021 17:26:07 by Hemant Gaikwad)

I need to create a new Extension module or need to add JavaScript widget can we have default function which can give random variable between defined range?

There are several solutions already in the Forge like for example: https://www.outsystems.com/forge/component-overview/677/randomizer-number-generator



Hi Daniel,

If we use extension (C# code) just to get random number will create performance issue for our applications instead we can simply use JavaScript code like I have used in my Forge component for Rock Paper Scissor game below.


However if we have inbuild function for Random Number in Outsytems will save our time as well as improve the performance.


Best Regards,

Hemant Gaikwad

Ok I get that it saves a little time not to create a client side action that uses JavaScript to get a random number, but that is  very little time. 

Regarding the performance client side, I don't see why a build in function (which will also use javascript) would be that more performant than the one you code yourself.


Hi Daniël Kuhlmann ,

Agree with you, we don't need random variable in real life applications. I was creating a game that's why I need it. However it will make developer's life easier little bit.

Merged this idea with 'Random Number Generator Function' (created on 19 Oct 2023 13:12:49 by Sanjay Bankar)

Hello Team,

It will be great if we can have Random Generator inbuilt function so that we can generate Random Numbers easily without using any Forge Components.

Thank you.

Hey Sanjay Bankar!

While it is true that there isn't a specific built-in function that generates (pseudo) random numbers, we do have a simple alternative that doesn't require any forge components...

The GeneratePassword built-in function allows you to generate strings of any desired length. If you set the second parameter to false, your string will only contain numbers. You can then parse that string into a number, using the Data Conversion functions.

GeneratePassword(6, False) - this is pretty much the same as saying that you want a random number between 0 and 999999.

You can even create your own wrapper function to call both built-in functions, for added convenience.

Enjoy!

Hi @Ricardo Marques 

Yes its true that using Generate Password function we can do it indirectly but i was looking for this specific mathematical function as i was having this specific requirement. 


Thanks 

Sanjay

Changed the category to
Builtin & User functions
Changed the status to
New
Merged this idea with 'Generate random number should be a built-in function' (created on 02 Jul 2019 13:27:46 by Sienna)

Generate password exists in the built-in functions, it's very surprising that generate random number doesn't.  Would be helpful to include it rather than having write/download a component.

I stumbled upon this recently as well and was surprised that this wasn't in the core of the platform and that I needed to use a Forge component.

Something as easy as generating a random decimal between 0 and 1 would be sufficient. If I need bigger number I can just multiply and round or trunc.

Yes, seems quite fundamental functionality.  Tbh it shouldn't be difficult to include an input of lower and upper number for the number generation, but as you say even just the bare bones would suffice.

Changed the category to
Builtin & User functions

I need the same. My use case is select random fake-client for demonstration of customer journey in credit application process. Now I use SQL Server (yes, I maybe know what you are thinking right now...) for this by getting 1 row from a view that triggers and so and so and returns a random client for my application demo. So... looking forward to this.

Yes, fingers crossed they implement it!  Only got 6 likes so far, but hopefully enough....

Yes! you're totally right.

is a good idea, it would be interesting for example RANDOM(3) where we would pass the numbers

Thats something that needs to be implemented. Good Idea

It;s already in the ODC version.. Just copy paste it in this one ;)

I'll be waiting for it