Alexa.Ki
(Alendromeda.ki)
August 19, 2022, 2:51pm
1
Hi, I can achieve this using blueprint library but how to do it not using
blueprint Library?
void AMyClass::GenerateUniqueNumber(FString& UniqueNumber)
{
float RandomFloat_1{};
FString RandomFloat_1_ToString{};
RandomFloat_1 = UKismetMathLibrary::RandomFloat();
RandomFloat_1_ToString = UKismetStringLibrary::Conv_FloatToString(RandomFloat_1);
float RandomFloat_2{};
FString RandomFloat_2_ToString{};
RandomFloat_2 = UKismetMathLibrary::RandomFloat();
RandomFloat_2_ToString = UKismetStringLibrary::Conv_FloatToString(RandomFloat_2);
FString Concat_Return{};
Concat_Return = UKismetStringLibrary::Concat_StrStr(RandomFloat_2_ToString, RandomFloat_1_ToString);
UniqueNumber = Concat_Return;
}
Rumzie
(Rumzie)
August 19, 2022, 2:58pm
2
You shouldn’t need KismetMathLibrary for this (Although you can use it)
Look into FMath::
To turn a float to string FString::SanitizeFloat(InFloat)
1 Like
Alexa.Ki
(Alendromeda.ki)
August 19, 2022, 3:04pm
3
Alexa.Ki:
RandomFloat
I don’t know what range returning the
randomfloat
node, using
FMath
I will need to define the static range which is not I want.
Rumzie
(Rumzie)
August 19, 2022, 3:07pm
4
KISMET_MATH_FORCEINLINE
float UKismetMathLibrary::RandomFloat()
{
return FMath::FRand();
}
This is your whole function
UniqueNumber = FString::SanitizeFloat(FMath::FRand()) + FString::SanitizeFloat(FMath::FRand())
2 Likes
Alexa.Ki
(Alendromeda.ki)
August 19, 2022, 3:10pm
5
Thank You very much for this solution, and still I have a question what values are sums
by FRand()
if this is possible to know or they are taken from memory the random numbers?
Rumzie
(Rumzie)
August 19, 2022, 3:17pm
6
I’m not sure I understand your question.
Alexa.Ki
(Alendromeda.ki)
August 19, 2022, 3:23pm
7
To be more specific lets look at the code
void AMyClass::GenerateUniqueNumber(FString& UniqueNumber)
{
UniqueNumber= FString::SanitizeFloat(FMath::FRand()) + FString::SanitizeFloat(FMath::FRand());
}
it will return a random string, so on what float range FRand
function is randomizing the floats? since It don’t need us to specify a range of floats.
or I am not doing it right and it need a float value like SanitizeFloat(FMath::FRand(MyFloatVariable))
?
Rumzie
(Rumzie)
August 19, 2022, 3:34pm
8
static FORCEINLINE float FRand()
{
// FP32 mantissa can only represent 24 bits before losing precision
constexpr int32 RandMax = 0x00ffffff < RAND_MAX ? 0x00ffffff : RAND_MAX;
return (Rand() & RandMax) / (float)RandMax;
}
Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.
A floating-point variable can represent a wider range of numbers than a fixed-point variable of the same bit width at the cost of precision. A signed 32-bit integer variable has a maximum value of 231 − 1 = 2,147,483,647, whereas an IEEE 754 32-bit base-2 floating-...
It will be the same as your blueprint since it’s calling essentially this function anyways. But it’s a number 0 to MAX where MAX is the largest value representable by an FP32 that the system allows. MAX is never lower than 32767 but as high as 0x00ffffff
Max is also determined at compile time using constexpr so you will know the MAX during compile time.
1 Like
Alexa.Ki
(Alendromeda.ki)
August 19, 2022, 3:53pm
9
amazing information, this is what exactly I wanted know, Thank You very much Sir for sharing this information , it helps very much
1 Like