Sponsored Content
Full Discussion: C++ templates
Top Forums Programming C++ templates Post 302885627 by Corona688 on Monday 27th of January 2014 02:05:58 PM
Old 01-27-2014
That logic doesn't work for integers because rand() / RAND_MAX just becomes zero. You don't need floor either, you just can take the remainder with %, which calculates like this:

Code:
0 % 10 = 0
1 % 10 = 1
2 % 10 = 2
3 % 10 = 3
4 % 10 = 4
5 % 10 = 5
6 % 10 = 6
7 % 10 = 7
8 % 10 = 8
9 % 10 = 9
10 % 10 = 0
11 % 10 = 1
...

...so rand() % max gets you a number between 0 and max-1, as long as max is significantly smaller than RAND_MAX.

Code:
int random(int max) { return(rand() % max); }

Your logic looks reasonable for float however. Again, max should be much smaller than RAND_MAX.

Last edited by Corona688; 01-29-2014 at 01:32 PM..
This User Gave Thanks to Corona688 For This Post:
 

8 More Discussions You Might Find Interesting

1. Programming

c++ templates problems in g++

what we have: class TClass { public: TClass(); }; template<class T> class FClass<T>: public T { public: FClass(); }; TClass::TClass() { // some code } template<class T> FClass<T>::FClass : T() { // some code } int main (int argc,char* argv) { (3 Replies)
Discussion started by: Marhinado John
3 Replies

2. Programming

site templates?

Are there any web site templates on CGI that allow like this forum software user registration and profiles. I dont need forum software i just need to register and keep profiles of my users on my site. Any suggestions? :confused: Thank you all. (1 Reply)
Discussion started by: solvman
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Templates

Hello, Anybody in here has any idea where I can get a template like this one for vBulletin. I have actually got my board but it just doesn't look good in the template that I have! Thanks anyway! him (2 Replies)
Discussion started by: him
2 Replies

4. HP-UX

Where are SAM user templates stored?

Hey, new here, so be nice! I'm trying to write a little script to automate the user creation process on one of our boxes. But I would like to be able to use the templates that we have set up in SAM. Is the information in these templates stored in a file somewhere, that I can reference in my... (5 Replies)
Discussion started by: paqman
5 Replies

5. Shell Programming and Scripting

Reading from Templates

I am trying to write a script that would retrieve specific information from a template. I have been trying to no avail for the longest. This is what I wrote and it's not working. cat filename | while read F5 F6 do if ] then echo $F5 $F6 fi done Here is the template (filename) CN ... (7 Replies)
Discussion started by: Ernst
7 Replies

6. Solaris

A compilation problem when using templates

Hello life savers, I'm having trouble compiling a specific program. The program was originally written for gcc and was compiled successfully under it. When trying to compile under Solaris 11, I get this error: "Hashtable.h", line 170: Error: Could not find a match for hash needed in... (2 Replies)
Discussion started by: yp515
2 Replies

7. Programming

Templates and header file

I have some C++ code and want to have the class declarations in a .h file and the implementation in the .cpp file. It seems however that for templates everything need to be put in the header (.h) file and will have problems if I try to separate the code to a .cpp file. Is this correct? Is... (1 Reply)
Discussion started by: kristinu
1 Replies

8. UNIX and Linux Applications

LibreOffice Templates Custom Distro

Hello, I have a custom Linux distro in which I'm trying to get templates for LibreOffice to ship by default. Is there a location they need to be placed or a file that needs to be edited? I've already tried using the template manager and add templates that way. I then copied /usr/templates/ and... (0 Replies)
Discussion started by: TheOuterLinux
0 Replies
vxusertemplate(1M)														vxusertemplate(1M)

NAME
vxusertemplate - create and administer user templates SYNOPSIS
vxusertemplate -d file [-f] create [template [template ...]] vxusertemplate [-f] create template_name [description=description] [rules=rules] [capability=capability(var=value,...)[,capability...]] vxusertemplate delete template vxusertemplate help [keywords | options | attributes] vxusertemplate list vxusertemplate print template [template ... ] DESCRIPTION
The vxusertemplate utility provides a command line interface for the creation and administration of user-defined or user templates that may be used with the Veritas Intelligent Storage Provisioning (ISP) feature of Veritas Volume Manager (VxVM). The operations that can be performed by vxusertemplate are selected by specifying the appropriate keyword on the command line. See the KEY- WORDS section for a description of the available operations. KEYWORDS
create Creates one or more user templates, whose definitions can be read from a definitions file or entered on the command line. delete Deletes a user template. help Displays information on usage, keywords, options and attributes. list Lists all user templates. print Prints detailed information about one or more user templates. OPTIONS
-d file Specifies a file that contains user template definitions -f Forces an operation that is not usually allowed by vxusertemplate. This option must be specified if the user template definition differs from the existing definition in the configuration database. EXAMPLES
Create the user templates ut1, ut2 and ut3 from the definitions in the file ut1.txt: vxusertemplate -d ut1.txt create ut1,ut2,ut3 Delete the user template myreliabletemplate: vxusertemplate delete myreliabletemplate List all user templates: vxusertemplate list Print details of the user template mytemplate: vxusertemplate print mytemplate EXIT STATUS
The vxusertemplate utility exits with a non-zero status if the attempted operation fails. A non-zero exit code is not a complete indicator of the problems encountered, but rather denotes the first condition that prevented further execution of the utility. SEE ALSO
vxtemplate(1M), vxvoladm(1M) Veritas Storage Foundation Intelligent Storage Provisioning Administrator's Guide VxVM 5.0.31.1 24 Mar 2008 vxusertemplate(1M)
All times are GMT -4. The time now is 12:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy