Guest User

Untitled

a guest
Jan 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <jni.h>
  2. #include <string>
  3. #include <time.h>
  4.  
  5. extern "C" JNIEXPORT jstring JNICALL
  6. Java_com_example_phi_myapplication6_MainActivity_stringFromJNI(
  7. JNIEnv *env,
  8. jobject /* this */) {
  9.  
  10. std::string hello = "Hello from C++";
  11. return env->NewStringUTF(hello.c_str());
  12.  
  13. }
  14. extern "C" JNIEXPORT jstring JNICALL
  15. Java_com_example_phi_myapplication6_MainActivity_getStringRandom(
  16. JNIEnv *env,
  17. jobject /* this */) {
  18.  
  19.  
  20. size_t length =10;
  21. auto randchar = []() -> char
  22. {
  23. const char charset[] =
  24. "0123456789"
  25. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  26. "abcdefghijklmnopqrstuvwxyz";
  27. const size_t max_index = (sizeof(charset) - 1);
  28. return charset[ rand() % max_index ];
  29. };
  30. std::string randomstr(length,0);
  31. std::generate_n( randomstr.begin(), length, randchar );
  32.  
  33. return env->NewStringUTF(randomstr.c_str());
  34.  
  35. }
Add Comment
Please, Sign In to add comment