Wszystkie dyskusje > Fora Steam > Off Topic > Szczegóły wątku
MarkLeonidas 26 czerwca 2018 o 12:13
Ue4 How do i create a random number generator?
Ue4 How do i create a random number generator? that can set a variable
Ostatnio edytowany przez: MarkLeonidas; 26 czerwca 2018 o 19:58
< >
Wyświetlanie 1-10 z 10 komentarzy
Blargo 26 czerwca 2018 o 12:16 
I'm assuming "UR4" means Unreal Engine 4?

Try asking their forums.
MarkLeonidas 26 czerwca 2018 o 14:28 
Początkowo opublikowane przez Dxpress:
I'm assuming "UR4" means Unreal Engine 4?

Try asking their forums.
i did and for over a hour i get no reply that suited my question
Ostatnio edytowany przez: MarkLeonidas; 26 czerwca 2018 o 14:35
DarkCrystalMethod 26 czerwca 2018 o 18:20 
Find an equivalent to randInt in the programming language of your choice. Might be in a math library. However if you only have random (which gives a floating point number from 0 to 1) then multiply the result by some scaling factor.
Need a D-20?
print convertToInteger( random() * 20 + 1 );

*I know nothing about Ur4. You'll have to search through the documentation yourself.
Ostatnio edytowany przez: DarkCrystalMethod; 26 czerwca 2018 o 18:21
Spíosra 26 czerwca 2018 o 19:51 
I'm assuming you mean for C++? A simple example...

#include <iostream> #include <random> int main() { // We want a seed, as with the rand() function. This'll get one for us std::random_device rd; // Generates pseudo-random numbers, seeded by random_device std::default_random_engine generator{rd()}; // Transforms output of generator into desired range // In this case, between 1 and 10, inclusive std::uniform_int_distribution<int> dist{1, 10}; // Get number int random_number{dist(generator)}; // Display random number std::cout << random_number << std::endl; return 0; }
MarkLeonidas 26 czerwca 2018 o 19:59 
Początkowo opublikowane przez Spíosra:
I'm assuming you mean for C++? A simple example...

#include <iostream> #include <random> int main() { // We want a seed, as with the rand() function. This'll get one for us std::random_device rd; // Generates pseudo-random numbers, seeded by random_device std::default_random_engine generator{rd()}; // Transforms output of generator into desired range // In this case, between 1 and 10, inclusive std::uniform_int_distribution<int> dist{1, 10}; // Get number int random_number{dist(generator)}; // Display random number std::cout << random_number << std::endl; return 0; }
not even close to gettting to that
Spíosra 26 czerwca 2018 o 19:59 
Początkowo opublikowane przez leonidas295:
Początkowo opublikowane przez Spíosra:
I'm assuming you mean for C++? A simple example...

#include <iostream> #include <random> int main() { // We want a seed, as with the rand() function. This'll get one for us std::random_device rd; // Generates pseudo-random numbers, seeded by random_device std::default_random_engine generator{rd()}; // Transforms output of generator into desired range // In this case, between 1 and 10, inclusive std::uniform_int_distribution<int> dist{1, 10}; // Get number int random_number{dist(generator)}; // Display random number std::cout << random_number << std::endl; return 0; }
not even close to gettting to that
What don't you understand?
MarkLeonidas 26 czerwca 2018 o 20:00 
Początkowo opublikowane przez BAT EMPEROR OF EGYPT:
Ur4 is an engine? There's usually a built in function to roll a random number in a language. Depending on the language, it could cast the result as a real number, not an int. So you have to cast back to int.

(I'm assuming you know enough to get what I'm saying)
i barely know anything really on blueprints
Spíosra 26 czerwca 2018 o 20:06 
What exactly are you trying to do?
DarkCrystalMethod 26 czerwca 2018 o 20:10 
Początkowo opublikowane przez leonidas295:
Początkowo opublikowane przez Spíosra:
I'm assuming you mean for C++? A simple example...

#include <iostream> #include <random> int main() { // We want a seed, as with the rand() function. This'll get one for us std::random_device rd; // Generates pseudo-random numbers, seeded by random_device std::default_random_engine generator{rd()}; // Transforms output of generator into desired range // In this case, between 1 and 10, inclusive std::uniform_int_distribution<int> dist{1, 10}; // Get number int random_number{dist(generator)}; // Display random number std::cout << random_number << std::endl; return 0; }
not even close to gettting to that
Back in my day we just read the millisecond timer to seed the randomizer and then we just called random as much as we wanted and life was good. You've got way more than any basic beginner could comprehend (the comments somewhat describe whats going on, but no newbie would come up with this). You're using iterators, namespaces, I'm guessing that dist{1, 10} is perhaps a modern macro expansion(I'm familiar with 1990's C++). Guess I have to get a newer coursebook.
Anyway, if that works then great, but do try to tune your code to something more suitable for a beginner and let them figure out how to use more language constructs and libraries as needed.

Anyway, we're presuming you (op) are using C++ and Ur4 as an addon library. If it came with sample code I guarantee there is one that does random numbers. Once you can hit the compile button and also get it to run right then try to dissect it. It should be a really really tiny program no matter which programming language it was written in.
Spíosra 26 czerwca 2018 o 20:20 
Początkowo opublikowane przez DarkCrystalMethod:
Początkowo opublikowane przez leonidas295:
not even close to gettting to that
Back in my day we just read the millisecond timer to seed the randomizer and then we just called random as much as we wanted and life was good. You've got way more than any basic beginner could comprehend (the comments somewhat describe whats going on, but no newbie would come up with this). You're using iterators, namespaces, I'm guessing that dist{1, 10} is perhaps a modern macro expansion(I'm familiar with 1990's C++). Guess I have to get a newer coursebook.
Anyway, if that works then great, but do try to tune your code to something more suitable for a beginner and let them figure out how to use more language constructs and libraries as needed.

Anyway, we're presuming you (op) are using C++ and Ur4 as an addon library. If it came with sample code I guarantee there is one that does random numbers. Once you can hit the compile button and also get it to run right then try to dissect it. It should be a really really tiny program no matter which programming language it was written in.
What exactly is difficult to comprehend? :/

We're not using iterators anywhere; we have to deal with the std namespace regardless, but I suppose a using statement could be done; and there are no macro expansions taking place anywhere - {} is the initializer list introduced in C++11.
This is all perfectly basic and standard C++. I thought justified in assuming that Gentle OP might be somewhat familiar with syntax and semantics.
Ostatnio edytowany przez: Spíosra; 26 czerwca 2018 o 20:52
< >
Wyświetlanie 1-10 z 10 komentarzy
Na stronę: 1530 50

Wszystkie dyskusje > Fora Steam > Off Topic > Szczegóły wątku
Data napisania: 26 czerwca 2018 o 12:13
Posty: 10