I want to populate a vector<int> with random values. I was on my to
doing this;
using namespace std;
vector<int> v( 10000);
vector<int>::it erator begin = v.begin();
vector<int>::it erator end = v.end();
iota(begin, end, 2);
random_shuffle( begin,end);
but it looks like "iota" is an old legacy thang not really in the stl.
What's the easiest/quickest way to fill a vector up with random values.
thanks very much.
G 4 10137 bo*@blah.com wrote: I want to populate a vector<int> with random values. I was on my to doing this;
using namespace std; vector<int> v( 10000); vector<int>::it erator begin = v.begin(); vector<int>::it erator end = v.end();
iota(begin, end, 2); random_shuffle( begin,end);
but it looks like "iota" is an old legacy thang not really in the stl.
What's the easiest/quickest way to fill a vector up with random values.
Something like
std::generate(v .begin(), v.end(), rand);
V
"bo*@blah.c om" <Gr**********@g mail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. . I want to populate a vector<int> with random values. I was on my to doing this;
using namespace std; vector<int> v( 10000); vector<int>::it erator begin = v.begin(); vector<int>::it erator end = v.end();
iota(begin, end, 2); random_shuffle( begin,end);
but it looks like "iota" is an old legacy thang not really in the stl.
No, there's no function 'iota()' (or 'itoa()') in the C++
(or C) standard library, nor has there ever been. But I'm
wondering: if there were such a function, why do you think
its parameters are iterators? IOW you're guessing. Don't
guess. If you envision a function you'd find useful, find
out if it exists, and *first* read its specification before
trying to use it. If it turns out it doesn't exist you'll
need to write it yourself. If you get stuck with that,
you can ask here for help.
What's the easiest/quickest way to fill a vector up with random values.
"Easy" depends upon your perception and skill level, 'quickest'
will depend upon your chosen algorithm and the 'quickness' of
the host platform.
Suggestion: Investigate 'std::generate( )' from <algorithm>
-Mike bo*@blah.com sade: I want to populate a vector<int> with random values. I was on my to doing this;
using namespace std; vector<int> v( 10000); vector<int>::it erator begin = v.begin(); vector<int>::it erator end = v.end();
iota(begin, end, 2); random_shuffle( begin,end);
but it looks like "iota" is an old legacy thang not really in the stl.
What's the easiest/quickest way to fill a vector up with random values.
thanks very much.
G
std::vector<int > v;
std::generate_n (std::back_inse rter(v),10000,r and);
--
TB @ SWEDEN
TB wrote: bo*@blah.com sade:
I want to populate a vector<int> with random values. I was on my to doing this;
using namespace std; vector<int> v( 10000); vector<int>::it erator begin = v.begin(); vector<int>::it erator end = v.end();
iota(begin, end, 2); random_shuffle( begin,end);
but it looks like "iota" is an old legacy thang not really in the stl.
What's the easiest/quickest way to fill a vector up with random values.
thanks very much.
G
std::vector<int > v;
Add
v.reserve(10000 );
here and it might even get a bit faster...
std::generate_n (std::back_inse rter(v),10000,r and);
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephen C. Waterbury |
last post by:
This seems like it ought to work, according to the
description of reduce(), but it doesn't. Is this
a bug, or am I missing something?
Python 2.3.2 (#1, Oct 20 2003, 01:04:35)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d1 = {'a':1}
>>> d2 = {'b':2}
>>> d3 = {'c':3}
|
by: Kyle |
last post by:
Got a tough one here for you SQL junkies.
I'm working on a website (in ASP) for a national greek/college
organization. All it's college chapters have greek chapter names,
i.e. Alpha Chapter, Delta Chapter, Delta Iota Chapter, Gamma Phi
Chapter, ect. ect.
I need the SQL to return the chapters in greek alphabet ordering. See
below:
1. Alpha
|
by: Christopher |
last post by:
This should be a quick one.
URL: http://cfa-www.harvard.edu/~cpilman/Stuff/flush.html
Code:
=============================
<!DOCTYPE HTML Public "-//W3C//DTD HTML 4.01//EN">
<HTML><Head><Title>Get my feet off the ground</Title>
<Meta HTTP-Equiv="Content-Type" Content="text/html; charset=us-ascii">
<Style type="text/css">
Body { font-size: 60px; }
|
by: Flzw |
last post by:
Alright, here is a simple function I coded, won't be hard understanding what
it does, and YES, I know, you will probably tell me it's awful code, I would
like to know how to write it better, maybe using stringstream ? here it is :
std::string IntToDiskSpace( int size)
{
if (size < 1024)
return IntToStr( size ) + " Bytes";
else if (size < 1048576)
return IntToStr( size / 1024) + "KB";
|
by: Christopher Benson-Manica |
last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.)
strchr() is to strrchr() as strstr() is to strrstr(), but strrstr()
isn't part of the standard. Why not?
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
| |
by: carlos |
last post by:
Curious:
Why wasnt a primitive exponentiation operator not added to C99?
And, are there requests to do so in the next std revision?
Justification for doing so:
C and C++ are increasingly used in low-level
numerical computations, replacing Fortran in newer projects.
Check, for example, sourceforge.net or freshmeat.net
But neither language offers a primitive exp operator.
|
by: fightwater |
last post by:
i wrote a program which uses the stl compose1 functor
but the compiler seems cannot find it
here is the code
//////////////////////////////////////////
#include <vector>
#include <numeric>
#include <ext/numeric>
#include <algorithm>
#include <ext/algorithm>
|
by: CardinalOmega007 |
last post by:
quelqu'un a ecrit:
iota delta iota omega tau iota epsilon sigma.
#Omega_7
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |