faker icon indicating copy to clipboard operation
faker copied to clipboard

feat: add binary and octal random number generation

Open luciferreeves opened this issue 3 years ago • 5 comments

Clear and concise description of the problem

faker.random.[...] already generates random number, bigInt, float, hexadecimal, etc. But it lacks octal and binary numbers. This can be added.

Suggested solution

This is an easy task. Either use the faker.datatype.hexadecimal() method as a reference or generate a random number using faker.datatype.number() and convert it into binary or octal.

A simple way to convert decimal to binary is:

console.log(Number((128).toString(2))) // 10000000

Similarly decimal to octal conversion is:

console.log(Number((128).toString(8))) // 200

(this is just one method to do so)

Alternative

No response

Additional context

No response

luciferreeves avatar Jan 17 '22 01:01 luciferreeves

Can I work on this?

mbokinala avatar Jan 17 '22 04:01 mbokinala

Also, I believe the title should be edited to read "add binary and octal random number generation"

mbokinala avatar Jan 17 '22 05:01 mbokinala

Needs to wait on the string module: #1341

(length: number) -> string

ST-DDT avatar Sep 08 '22 16:09 ST-DDT

I saw that the open PR was closed, is @mbokinala going to work on this feature? Can I work on it?

Minozzzi avatar Sep 08 '22 17:09 Minozzzi

Either way please wait for the StringModule before you start with the implementation.

ST-DDT avatar Sep 08 '22 17:09 ST-DDT

Any updates regarding the state of this issue? if the StringModule update is live then this would be a useful addition. If possible, I would like to champion the issue as well

SamRett avatar Oct 16 '22 03:10 SamRett

We are currently updating and reviewing the string module PR. It will probably take a few more days before this can be started. https://github.com/faker-js/faker/pull/1155

@Minozzzi asked first. Are you still interested in this or can @SamRett take your spot?

ST-DDT avatar Oct 16 '22 06:10 ST-DDT

If @Minozzzi would still like to champion it, that's perfectly okay as well :). Wanted to throw my name in the metaphorical hat, so let me know what you guys think! He bid first so I don't want to unduly take away the right.

SamRett avatar Oct 16 '22 07:10 SamRett

Hi @SamRett I've been very busy the last few days. So, you can have fun with this task ;)

Minozzzi avatar Oct 16 '22 19:10 Minozzzi

Thank you! Please let me know when the StringModule update is ready. Once it is out, I can begin development/testing!

Until then, thank you both!

SamRett avatar Oct 16 '22 22:10 SamRett

@xDivisionByZerox can you provide info about how the progress of #1155 is going? If you do not have the time currently, also let us know and someone else can take it over

Shinigami92 avatar Oct 17 '22 12:10 Shinigami92

@xDivisionByZerox can you provide info about how the progress of #1155 is going? If you do not have the time currently, also let us know and someone else can take it over

Feel free to take #1155 if you have time on your hand.

xDivisionByZerox avatar Oct 17 '22 13:10 xDivisionByZerox

Feel free to take #1155 if you have time on your hand.

Yeah, thx for letting me know Will take it over immediately

Shinigami92 avatar Oct 17 '22 16:10 Shinigami92

@SamRett you can start

Shinigami92 avatar Oct 18 '22 17:10 Shinigami92

Faker Team, and @Shinigami92 (tagging so this gets seen)

So, a quick explanation. I have had difficulties testing as well as other issues regarding simply time so I devoted as much time and work as I could, however, I am not personally satisfied with the final result of my work. This is due to the fact that I have been unable to test my code, thus leaving a large question mark regarding its implementation and working status. Regardless, I tried my best to stick to the conventions that you guys have laid out so it could potentially be used in the final implementation.

Due to this, I have decided to simply link my forked version of Faker so that whoever is assigned the issue after me can see what I wrote, and simply take that to reduce their own workload. Normally I would make a Pull Request, however, in light of my own dissatisfaction with the work I do not wish to make more work on your end.

Working with you all was an amazing experience and I really enjoyed learning about Faker! This is truly an amazing project, and I wish you all the best, especially with version 8 looming over the horizon. It will be really cool to see how Faker evolves from here.

SamRett avatar Dec 09 '22 23:12 SamRett

Thanks for letting us know. And thanks for the time you put into it.

ST-DDT avatar Dec 10 '22 09:12 ST-DDT

Hi, can I be assigned to this issue? I already did it locally and would like to create the PR

pladreyt avatar Jan 02 '23 10:01 pladreyt

Sure, go ahead.

ST-DDT avatar Jan 02 '23 10:01 ST-DDT

Unless I am missing something, I think this can be closed now. It was great contributing here, thanks !

pladreyt avatar Jan 07 '23 19:01 pladreyt

Fixed via #1710 and #1708

ST-DDT avatar Jan 07 '23 20:01 ST-DDT