I need to generate a 100 digit number, but i cant find the method or something like this, I search in a lot of foruns and online tutorials and I can't find this. Someone can help me?
I need help with RandomNumberGenerator
- Edited
Do you mean a string with 100 random digits (0-9)? And you don't want to perform any math operations on it?
Here's one way of doing it:
var s: String = ""
for _i in range(100):
s += str(randi() % 10)
print_debug(s)
If you want the string to be different each time the code is executed, call randomize() first. But randomize() should only be called once in the project.
QUOTE from https://docs.godotengine.org/en/stable/classes/class_randomnumbergenerator.html#class-randomnumbergenerator-method-randi
"int randi ( )
Generates a pseudo-random 32-bit unsigned integer between 0 and 4294967295 (inclusive)."
QUOTE ENDS
So, according to this, the greatest no. digits per random (int) number is 10.
- Edited
No, this cannot be done with standard tools. Because there is no representation for any integer larger than 64 bit in most languages. C and C++ have both a long long type, but that's defined as having at least 64 bit, and more is not guaranteed. Any way, this is way too low.
In GDscript you will need to write your own generator. The simplest form will be to generate one hundred digits as suggested by DaveTheCoder , but you still need a data structure to store these and perform any arithmetic operation down the line you might want to do with it. Anything more sophisticated needs more calculus. Random numbers of large sizes are used in cryptography contexts. And of course there are online generators if this is a one time thing.
Python can handle and do arithmetic with large numbers, but is very slow with it. You can write a Python library for such large random numbers (if it doesn't already exist) and integrate that into Godot. There should be a way to do so.
@DaveTheCoder method would be the easiest way to do this.