Re: random number generator

From: G_cowboy (vvosen_at_cpinternet.com)
Date: 02/11/04


Date: Wed, 11 Feb 2004 00:30:45 -0500

Jerry Coffin wrote:

> In article <102jfimbadu52e4@corp.supernews.com>, vvosen@cpinternet.com
> says...
>> what library would I use to generate a random number within a range
>> and what would be the function call?
>
> Code for this has been posted fairly recently; fortunately, it's short
> enough that I guess one more time wouldn't hurt:
>
> #include <stdlib.h>
>
> int rand_lim(int limit) {
> /* return a random number between 0 and limit inclusive.
> */
>
> int divisor = RAND_MAX/(limit+1);
> int retval;
>
> do {
> retval = rand() / divisor;
> } while (retval > limit);
>
> return retval;
> }
>
>> I'm building this data base file
>> that contains filenames for display but I want them to be randomly
>> selected
>> as well as possible. I plan on storing the filenames within an array
>> and would like to present the files(pics) in a sequence while keeping
>> track of how many times they were displayed so that no file was displayed
>> twice. Yea, I've got my work cut out for me and I'm chewing on c++.
>
> For this job, you might want to start with something like a vector of
> strings, and use random_shuffle to put them in a random order. Then you
> can simply keep track of the current spot on the vector, and when you
> need to show another randomly-chosen name, you just use the next one in
> the vector.
>

Problem with shuffling is that the filenames have pairs so shuffling would
just confuse me and the program wouldn't be able to keep track of any
corrolaries that I need to work with. I'm needing the display random, not
the file structure. As to the code you included, thanks anyway, but I'd
rather try figuring out how srand() works before I try that.



Relevant Pages

  • Re: One more try to get help on 8.3 filenames in XP
    ... Access does display the filenme in long form. ... The app plays the file by opening Digital Orchestrator or setting focus if ... win 98 the file plays in XP I get a error as the file list ... website with short filenames. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Turnign greek-iso filenames => utf-8 iso
    ... # Convert wrongly encoded filenames to utf-8 ... encoding = guess_encoding ... # Rename the file to something which ought to be UTF-8 clean. ... # Display ALL files, each with its own download button ...
    (comp.lang.python)
  • Re: Filenames and details blank in Windows Explorer until selected
    ... guess was right - the font colour was set to white since when the ... I wasn't interested in any of the display settings). ... The folder list in the left hand pane displays correctly, ... then filenames and details are displayed as expected. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Turnign greek-iso filenames => utf-8 iso
    ... # Convert wrongly encoded filenames to utf-8 ... encoding = guess_encoding ... # Rename the file to something which ought to be UTF-8 clean. ... # Display ALL files, each with its own download button ...
    (comp.lang.python)
  • [OT] Re: calculator prototype
    ... Jerry Coffin wrote: ... > lagunasun wrote: ... > minimal calculation and only needs to run a numeric display ...
    (comp.lang.cpp)