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

  • SEARCH
  • Home
  • 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 9255457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:43:19+00:00 2026-06-18T11:43:19+00:00

I have a probelm :( i wanna make a program wich gives a random

  • 0

I have a probelm πŸ™ i wanna make a program wich gives a random number πŸ™‚ i don’t want use rand() function πŸ™‚ i wanna make one for me then turn it to a function πŸ˜‰ for educational purpose πŸ™‚
but i have a problem πŸ™ see my code πŸ™‚

#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <windows.h>

#define MIN 0
#define MAX 99999

using namespace std;

typedef struct _RANDOM_INFO{
    DWORD random;
    DWORD min;
    DWORD max;
} RANDOM_INFO, * LPRANDOM_INFO;

void Error(LPSTR lpErrorMessage){
    cout << lpErrorMessage << endl;
    exit(EXIT_FAILURE);
}

void GetRandom(LPVOID lpParam){

    DWORD dwListSize = 10000, min = 0, max = 99999;
    LPDWORD lpRandom = (LPDWORD)lpParam;
    LPSTR lpFileSelf, lpKernel, lpNtdll;    
    HMODULE hFileSelf = NULL, hKernel = NULL, hNtdll = NULL;

    hFileSelf = (HMODULE) GetModuleHandle(NULL);
    hKernel = (HMODULE) GetModuleHandle("kernel.dll");
    hNtdll = (HMODULE) GetModuleHandle("ntdll.dll");

    lpFileSelf = (LPSTR) hFileSelf;
    lpKernel = (LPSTR) hKernel;
    lpNtdll = (LPSTR) hNtdll;

    while(1){
        DWORD i;
        for(i = 0; i <= dwListSize; i++){
            *lpRandom = (DWORD)lpFileSelf[i];   
        }
        i = 0;
    }

    return;
}

int main(int argc, char **argv)
{
    DWORD random = 0;

    DWORD getRandomThreadId = 0;

    HANDLE hGetRandomThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetRandom, &random, 0, &getRandomThreadId);
    if(hGetRandomThread == INVALID_HANDLE_VALUE)
        Error("Cannot make a random list.");

    getch();

    cout << random << endl;
    Sleep(1500);

    return 0;
}

The variable should get a value when and print it but i always i get 0 and a windows error can someone tell me why??? and another problem when i try to use the variable hKernel in the GetRandom function i get an error too πŸ™ but it works fine whith hFileSelf and hNtdll !!!! is kernel protected from reading???

Note : this is not a random number generation πŸ™‚ its just a way to get a number from the memory when the user click on the enter on his keyboard :), and its not always the same time for all users so its not always the same pointer in memory πŸ™‚ i hope u understand what i want do πŸ™‚ sorry for my bad englush πŸ™‚ just help me to fix the problem πŸ™‚

Thank u πŸ™‚

  • 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-18T11:43:20+00:00Added an answer on June 18, 2026 at 11:43 am

    Your GetRandom() function does not have the correct signature for a CreateThread() callback procedure. Try this instead:

    #include <stdio.h>
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    
    #define MIN 0
    #define MAX 99999
    
    using namespace std;
    
    typedef struct _RANDOM_INFO
    {
        DWORD random;
        DWORD min;
        DWORD max;
    } RANDOM_INFO, * LPRANDOM_INFO;
    
    void Error(LPSTR lpErrorMessage)
    {
        cout << lpErrorMessage << endl;
        exit(EXIT_FAILURE);
    }
    
    HMODULE hFileSelf = (HMODULE) GetModuleHandle(NULL);
    
    DWORD WINAPI GetRandomThreadProc(LPVOID lpParam)
    {
        LPDWORD lpRandom = (LPDWORD) lpParam;
    
        DWORD dwListSize = 10000, min = 0, max = 99999;
        LPBYTE lpFileSelf = (LPBYTE) hFileSelf;
    
        while (1)
        {
            for (DWORD i = 0; i <= dwListSize; ++i)
            {
                *lpRandom = (DWORD) lpFileSelf[i];   
            }
    
            Sleep(0);
        }
    
        return 0;
    }
    
    int main(int argc, char **argv)
    {
        DWORD dwRandom = 0;
        DWORD dwRandomThreadId = 0;
    
        HANDLE hGetRandomThread = CreateThread(NULL, 0, &GetRandomThreadProc, &dwRandom, 0, &dwRandomThreadId);
        if (hGetRandomThread == INVALID_HANDLE_VALUE)
            Error("Cannot make a random list.");
    
        do
        {
            getch();
            cout << dwRandom << endl;
        }
        while (WaitForSingleObject(hGetRandomThread, 0) == WAIT_TIMEOUT);
    
        CloseHandle(hGetRandomThread);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a puzzling problem with trying to make an ajax/static state program. What
I want to make IPC, but I cannot use blocking mechanism (SendMessage, PIPE, TCP),
in my Zend Framework App i wanna use Dojo Form. I have problem with
Possible Duplicate: Splitting a string in C++ I have this vector function from one
I wanna have a push function on my app. My app works with a
im new in android programming.. i have a problem here. i wanna make an
I have lots of data in database and I wanna make a statistics from
I have a problem using Regex, in ASP.NET website. I wanna get the counts
I have readed something about it i wanna to do some implementation using this.
I m trying to make feed system for my website, in which i have

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.