Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:12:24+00:00 2026-06-13T22:12:24+00:00

Need to generated some random 10 byte length string in c function and call

  • 0

Need to generated some random 10 byte length string in c function and call the function from objective-c. So, I’m creating a pointer to uint8_t and passing it to C function. The function generates random bytes and assigns them to *randomString. However, after returning from function to objective-c randomValue pointer points to NULL.

Here’s my random function in C:

void randomString(uint8_t *randomString)
{
  randomString = malloc(10);

  char randomByte;
  char i;
  for (i = 0; i < 10; i++) {

    srand((unsigned)time(NULL));
    randomByte = (rand() % 255 ) + 1;
    *randomString = randomByte;
    randomString++; 
  }
} 

Here’s objective-c part:

uint8_t *randomValue = NULL;
randomString(randomValue); //randomValue points to 0x000000

NSString *randomString = [[NSString alloc] initWithBytes:randomValue length:10 encoding:NSASCIIStringEncoding];
NSLog(@"Random string: %@", randomString);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:12:26+00:00Added an answer on June 13, 2026 at 10:12 pm

    Pointers are passed by value, so randomValue will remain NULL after the call of randomString. You need to pass a pointer to a pointer in order to make it work:

    void randomString(uint8_t **randomString) {
        *randomString = malloc(10);
        // ... the rest of your code goes here, with an extra level of indirection
    }
    
    uint8_t *randomValue = NULL;
    randomString(&randomValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, a string generated its length can varying from 1 to 100
I need to generate a large random string to encrypt some passwords with in
I have a wordpress-generated page where I need some posts (in a specific category)
I need to generate quickly lots of random numbers from binomial distributions for dramatically
Writing a function to generate and push some random data inside of the unknown
I need to generate random numbers based on multiple seed values, need some ideas
I've generated a graph of random numbers (standard deviation 1, mean 0). I need
I need to generate some token that can only take on a range of
I need to generate some 5x6 matrices in MATLAB. They need to consist of
Hi I need to generate some files on server side and return them to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.