create src/Models/Float.php
Closed this issue · 7 comments
Create new Model class for float number (with decimals).
Start from src/Models/Integer.php as "template"
- file: src/Models/Float.php
- class: Float
- namespace: HiFolks\RandoPhp\Models
- attribtues: min (default 0 )and max (default 1), for lowest char and highest char
- attributes: decimals , default (2 decimal)
- generate: genrate a float number considering min, max, decimals attributes;
Example:
$float = Randomize::float()->decimal(5)->min(0)->max(100)->generate();
It generates something like this: 12.42213
Can I take care of this issue?
Can I take care of this issue?
Sure @jirkavrba ! Thank you! Welcome!
Do you have some ideas about how to generate floats in a reliable way?
My guess would be to generate an integer within the given min-max range, and then generate the part after comma by using mt_rand
and mt_getrandmax
, then tripping it with round
with the given decimal precision
So the final solution seemed to be generating integers and moving the exponent, as generating random floats with mt_rand
and mt_getrandmax
couldn't guarantee the required decimals
Hi @jirkavrba thank you!
I appreciated also the unit tests. Thank you very much!!!
I opened a new issues , just to have an example about "how to use Float Model" #38
I will have a look at it, I also noticed that some tests don't have 100% coverage so I might also improve that
I will have a look at it, I also noticed that some tests don't have 100% coverage so I might also improve that
Great thank you! Please take a look on the issues if you want to add new tests. I opened some issues about adding tests and some of that are already assigned.